Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by IlyaM (Parson)
on Sep 08, 2002 at 19:48 UTC ( #196083=note: print w/ replies, xml ) Need Help??


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

IMHO it just too easy to do such mistake. Most of Perl operators that automagically assign to $_ (for/foreach, map, grep) do localize it so it doesn't affect outer scope. On the other hand magic in while(<>) construct doesn't work same way while newbie to Perl can expect Perl to do it. Frankly I've never though about such side effect of this construct before and I think I can say that I'm seasoned Perl programmer.

Anyway what I did wrong? I just have simple map construct (I've posted snipplet of real code in other reply to this thread) and that error was very confusing. Most of the time Perl does right thing with scopes and badly written external to my code module cannot affect my code so destructively. Usually I can treat them as black boxes.

Now instead of just writting use Net::DNS in my modules I will have to patch them to have something like { local $_; require Net::DNS } (until Net::DNS is fixed).

--
Ilya Martynov (http://martynov.org/)


Comment on Re: 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://196083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-07-29 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls