Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: String replace

by tirwhan (Abbot)
on Nov 29, 2005 at 18:14 UTC ( [id://512738]=note: print w/replies, xml ) Need Help??


in reply to String replace

I presume you're trying to replace each string with a specific other string, i.e. XXX is always supposed to be replaced by AAA etc.
my $text="The respondent uses the following products XXX, YYYYYYYYY, Z +ZZZZZZ around the house and they are considering using QQQQQQQ too. T +hey are particularly impressed with ZZZZZZZ."; my %replace=( "XXX" => "AAA", "YYYYYYYYY" => "BBBBBB", "ZZZZZZZ" => "CCCCCC", "QQQQQQQ" => "DDDDDDDD"); my $search=join '|',keys %replace; $text=~s/($search)/$replace{$1}/g; print $text;

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found