in reply to while(<>) { ... } considered harmful

I probably wrong but I'd say map is considered harmful.
I use while(<>){...} all the time but never use map.
Would I run into this problem if I avoid using
map? I guess I just don't understand map.
Why use map?
  • Comment on Re: while(<>) { ... } considered harmful

Replies are listed 'Best First'.
Re^2: while(<>) { ... } considered harmful
by Aristotle (Chancellor) on Sep 08, 2002 at 05:15 UTC
    Because something like my @idx = map /(id\d+)/, @items; is a lot more natural than
    my @idx; /(id\d+)/ && push @idx, $1 for @items;
    (which is already pushing legibility). Basically when you build one list out of another, non-destructively, map is the ticket. It can be in other cases as well, but those can often go either way.

    Makeshifts last the longest.

Re: Re: while(<>) { ... } considered harmful
by IlyaM (Parson) on Sep 09, 2002 at 09:42 UTC
    I disagree with saying that map is considered harmful. As I noted in other reply in this thread its behaviour is consistent with other Perl operators: for/foreach and grep. In my opinion it is while(<>)'s magic is wrong. It should localize $_ so it doesn't affect outer scope.

    --
    Ilya Martynov (http://martynov.org/)