Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by greenFox (Vicar)
on Jul 11, 2002 at 05:28 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2025-01-15 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (48 votes). Check out past polls.