Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: use warnings => Use of uninitialized value...

by kudra (Vicar)
on May 24, 2006 at 08:49 UTC ( #551302=note: print w/ replies, xml ) Need Help??


in reply to use warnings => Use of uninitialized value...

I like to keep warnings on, because sometimes it is a bug when a variable is undefined, and I can't always rely on strict to tell me (for instance if I typo a hash key).

Other times I expect that a variable could be undefined. In those instances, I explicitly allow for that option:

if (defined($hash{key}) && $hash{key} =~ /\d+/) { ... }
Other times I will set the variable to a false but defined value, such as an empty string or zero. It depends upon the context; often false and undefined are logically interchangeable, but other times they are not (in the above example, 0 has a different meaning than undef).

It doesn't hurt to be explicit about your expectations; it can make things easier for the next person.


Comment on Re: use warnings => Use of uninitialized value...
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2015-07-31 05:38 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 (274 votes), past polls