Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: How can I extract part of a string after a specific character

by greenFox (Vicar)
on Jul 11, 2002 at 05:28 UTC ( #180949=note: print w/replies, xml ) Need Help??

in reply to How can I extract part of a string after a specific character

I suspect split would be your best choice-

# split my ($key, $string1) = split /=/, $_, 2; print "$key, $string1\n";

Though there are other ways-

#re 1 /^TITLE=(.*)/; my $string2 = $1 || ''; print "$string2\n"; #re 2 (my $string3 = $_) =~ s/TITLE=//; print "$string3\n"; # substr my $string4 = substr($_, 6); print "$string4\n";

Just as examples. Which method you choose will depend on what else is going on in your program and what the most general case of your expression is. If it is *always* TITLE="some string" I might use substr. If it was (for example) "some text in upper followed by an equals followed by some string ending in a numeric" *and* I had to ignore other lines that include "=" I might use an regular expression.

my $chainsaw = 'Perl';

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180949]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-12-01 01:07 GMT
Find Nodes?
    Voting Booth?