Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by dws (Chancellor)
on Sep 07, 2002 at 23:37 UTC ( #195930=note: print w/ replies, xml ) Need Help??


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

Since   map { substr($_, 1, 1) = "foo" } qw(bar baz);
and   grep { substr($_, 1, 1) = "foo" } qw(bar baz);
both exhibit the problem you've observed, perhaps the advice might better be phrased

Don't write to $_ from within map { } or grep { }

local $_; is one way to avoid writing to it, since the 'it' is now different.


Update: Hm.. It's a bit worse than that.   foreach ( qw(foo) ) { $_ = 1 }
also exhibits the problem.


Comment on Re: while(<>) { ... } considered harmful
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-07-07 06:42 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 (87 votes), past polls