in reply to Bug? with reverse in map

map does, indeed, evaluate its BLOCK in list context. This is so you can say stuff like

my $n=0; my %position = map {$_ => $n++} @list

The simple fix is to make your block evaluate reverse in scalar context: map { scalar reverse($_) } @list.

Replies are listed 'Best First'.
Re: Re: Bug? with reverse in map
by Jasper (Chaplain) on May 14, 2002 at 16:34 UTC
    I'm appalled that the first thing I thought of to scalarify the return from reverse was:
    my @list2 = map { ~~reverse } @list;
    Too much golf!