Am 2011-09-08 12:22, schrieb John W. Krahn:
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

thx for all replies
by now i have realized, that i misunderstood tr///. i'll stick with s///.

matthias


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to