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

Re: search and replace from array values

by Tomte (Priest)
on Dec 06, 2005 at 13:36 UTC ( #514445=note: print w/ replies, xml ) Need Help??


in reply to search and replace from array values

hmm,

@search = ("red", "orange", "blue"); @replace = ("yellow", "black", "green"); $text = "my pig is red, my orange is orange and the sky is blue"; foreach (0..$#search) { $text =~ s/$search[$_]/$replace[$_]/; } print $text,"\n" __END__ my pig is yellow, my black is orange and the sky is green
To replace every ocasion in text, use the g-modifier (s///g)

not a beauty, but works...

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus


Comment on Re: search and replace from array values
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-22 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls