Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Substitute values

by manoj_speed (Priest)
on Mar 13, 2009 at 12:56 UTC ( #750392=perlquestion: print w/ replies, xml ) Need Help??
manoj_speed has asked for the wisdom of the Perl Monks concerning the following question:

Hi friend

I used a perl program to substitute values. I used two methods for substitution (as tr/a//d and s/a//g ). Which one will be the faster?

Comment on Substitute values
Re: Substitute values
by vinoth.ree (Parson) on Mar 13, 2009 at 13:00 UTC

    tr/// only replaces characters for characters. It is very limited but faster than s/// for simple character replacing. s/// is a full blown regexp that can use all of perls various options for pattern matching and substitution. For example if all you wanted to do was replace all A's with Z's tr is the better choice: tr/A/Z/; tr/// can't even use case insensitive matching so to replace all 'A' and 'a' with 'Z' you have to do this: tr/aA/Z/; the only useful option with tr/// is the range operator: tr/a-z/A-Z/

    For more information see the link

    Click Here

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-09-19 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls