It also returns the last value of the inner block, for each element of the provided list. The output of '1111001' matches those members of @words that have the - character removed from them. Hmm. print join "\n", map { tr/-//d; $_ } map { split/\s+/ } @words; or print join "\n", map { tr/-//d; split/\s+/; $_ } @words ; work. (You can even remove the $_ statement in the second one -- I left it in there so there would be no doubt about the last statement in the block.)
The first example you provided works correctly because the last statement of the first map block (which is the last one evaluated) returns the words. The second one does not, because, in the scalar context, tr/// returns the number of successful transliterations (1 or 0 in your example).
(Adam pointed out that my original explanation of tr/// fit the facts, but was wrong.)
In reply to Re: Fun with learning maps
by chromatic
in thread Fun with learning maps
by jeffa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |