The main difference is speed. tr/// doesn't do interpolation or use the regex engine, so it is blazingly fast in comparison. It's very good for transliterating characters (if you've ever studied a dead language that didn't use the Arabic alphabet, you'll understand).
s/// is more flexible -- it uses the regex engine and allows character classes. It can also perform nearly abitrarily complex interpolation.
You can get by with just s///, so if you're in doubt, go for it. Just be aware that, used correctly, tr/// will run rings around it. | [reply] |
I also habitually use s/// where I could use tr///.
The main difference is with s/// you can use regular expressions, while in tr/// you cannot.
Also (from the camel book) "the translation table is built at compile
time, neither the SEARCHLIST nor the REPLACEMENTLIST are subject to double quote interpolation."
So that means:$str =~ tr/$mylist//d; Will delete
all occurances of "$, m, y, l, i, s, t" in $str. Probably not what you want.
Also since the tr/// cannot use regex's it is usually a lot faster.
I did a benchmark to that here.
| [reply] [d/l] |
damnit, wrong link again... sorry!
| [reply] |