Because the transliteration table is built at compile time, neither the SEARCHLIST nor the REPLACEMENTLIST are subjected to double quote interpolation. That means that if you want to use variables, you must use an eval():
eval "tr/$oldlist/$newlist/"; die $@ if $@; # or eval "tr/$oldlist/$newlist/, 1" or die $@;
In reply to Re: How to use a variable in tr///
by inman
in thread How to use a variable in tr///
by perl-novice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |