Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: tr///

by archen (Pilgrim)
on Jan 24, 2002 at 22:53 UTC ( #141279=note: print w/ replies, xml ) Need Help??


in reply to Replacing multiple words in a regex

$str = tr/green,blue/$yellow,$RED/;

The above post states the answer to your question, but I'd point out another thing. In the above code you're using the wrong operator. in order to bind tr///, s///, or m/// to a string you need to use the =~ operator like so:

$str =~ tr/g/o/;

It's a common mistake so maybe it's just a typo when you submitted the code. The way you have it written, tr/// is in scalar context and will just return how many times it replaced something.

Edited: fixed typo -- japhy

Update:See? I told you it was a common mistake! ;) . Maybe I need another cup of coffee... or need to stop using the default variable so much..


Comment on Re: tr///
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2015-07-30 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls