Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2018-06-25 07:00 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.