On 2011-01-11 11:44, Uri Guttman wrote:

these are equivilent:

        my @out = grep /foo/, @in ;
        my @out = map { /foo/ ? $_ : () } @in ;

Indeed equivalent. There is a difference though
in what comes out of map and grep:

perl -wle'
    my @in = 1 .. 4;
    print "@in";

    ++$_ for map { $_ % 2 ? $_ : () } @in;  # copies
    print "@in";

    ++$_ for grep { $_ % 2 } @in;  # aliases
    print "@in";
'

1 2 3 4
1 2 3 4
2 2 4 4


--
Ruud

--
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