Yes. The terse explanation can be perused at
perlop, but here is simple explanation
in the meantime:
tr/// is the transliteration operator. It is used to
convert all occurances of one character class to another:
tr/0-9/A-J/
s/// is the substitution operator. It replaces a pattern
with some replacement string:
s/foo/bar/
The differences in the results can be subtle.
A great explanation of
when to use to which (don't rule out substr as a
solution either) can be found at Code Smarter.
Jeff
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
| [reply] [d/l] [select] |
If it's a single character to other single character, or single character to empty mapping, without regard to surrounding character context, tr/// will certainly beat s///, as it's the simpler operator to do so.
So, use tr/// if it can do the job, otherwise use s///.
-- Randal L. Schwartz, Perl hacker | [reply] |
Yes indeed - mainly because tr/// doesn't understand regular
expressions. | [reply] |
tr/// does transliteration... it maps characters to other characters.
s/// will take a pattern and replace the pattern...
This will explain it in much more detail...
Best of luck!
UPDATE: Listen to jeffa, he makes much more sence than I... but the best way to understand the difference is still Here
.mincus telnet://bbs.mincus.com
| [reply] |