Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-05 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls