Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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]
[Tanktalus]: Does anyone have a link to somewhere that explains why it's a bad idea to spit out text on stdout/stderr in the login scripts when it's a non-interactive shell?

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-04-25 21:15 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (464 votes). Check out past polls.