Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: while(<>) { ... } considered harmful

by Anonymous Monk
on Sep 08, 2002 at 04:14 UTC ( #195978=note: print w/replies, xml ) Need Help??

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 (

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://195978]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2016-10-23 06:57 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (300 votes). Check out past polls.