strat has asked for the wisdom of the Perl Monks concerning the following question:
I've got a problem with reverse in map:
The code above works as I want it to work: it reverses every element in the list as string. But this code below doesn't reverse the strings:C:\ce3\bin>perl -w my @list = qw(abc2 abc3 abc1 abc0); my @list2 = map { my $r = reverse($_); $r } @list; # scalar context print "@list2"; ^Z 2cba 3cba 1cba 0cba C:\ce3\bin>
I think, in the second example, the reverse-function is somehow used in list-context, not in scalar context. Is this a perl bug, or am I the bug (as usual)?C:\ce3\bin>perl -w my @list = qw(abc2 abc3 abc1 abc0); my @list2 = map { reverse($_) } @list; print "@list2"; ^Z abc2 abc3 abc1 abc0
I've run these codes under Activestateperl 631 (Win2k) and Perl 5.005_03 under Solaris.
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bug? with reverse in map
by ariels (Curate) on May 14, 2002 at 13:29 UTC | |
by Jasper (Chaplain) on May 14, 2002 at 16:34 UTC | |
|
Re: Bug? with reverse in map
by Joost (Canon) on May 14, 2002 at 13:31 UTC |