Matthias Leopold wrote:
perl -e '$_ = "ao"; tr/"a","o"/"b","p"/; print $_."\n";'
works as (i) expected -> "bp"
from perlop: tr/SEARCHLIST/REPLACEMENTLIST/cds
LIST in SEARCHLIST and REPLACEMENTLIST refers to a list of characters.
If we rearrange your example above:
perl -e '
$_ = "ao";
tr{"a","o"}
{"b","p"};
print $_."\n";
'
You get: the character " is replaced with the character "
and the character a is replaced with the character b
and the character " is replaced with the character "
and the character , is replaced with the character ,
and the character " is replaced with the character "
and the character o is replaced with the character p
and the character " is replaced with the character "
And if you have multiple characters the same in the SEARCHLIST then only
the first one will have any effect in the REPLACEMENTLIST.
So that could be written more simply and efficiently as:
tr/ao/bp/;
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/