Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: A refactoring trap

by ihb (Deacon)
on Aug 23, 2005 at 21:47 UTC ( #486026=note: print w/ replies, xml ) Need Help??


in reply to Re: A refactoring trap
in thread A refactoring trap

Dispite that many has pointed out that

while (my $line = <DATA>) { ... } while (defined (my $line = <DATA>)) { ... }
are identical, your first remark is true. The problem lies elsewhere:
while (<DATA>) { ... }
doesn't localize $_ and thus leaves $_ undefined after the loop.
while (my $line = <DATA>) { ... }
doesn't suffer from this as it doesn't touch $_.

If put in a subroutine this innocent little bug cause a serious headache while trying to find out why $_ all of a sudden is undefined.

ihb

See perltoc if you don't know which perldoc to read!


Comment on Re^2: A refactoring trap
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2015-07-01 16:31 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 (11 votes), past polls