Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by liverpole (Monsignor)
on May 24, 2006 at 18:44 UTC ( [id://551435]=note: print w/replies, xml ) Need Help??


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

A true story ...

Several weeks ago, a coworker of mine asked me to lend him my eyes to try to find a problem in a Perl script he was debugging.  Now this coworker is quite intelligent, and although, as senior architect, he's more of a C expert, and doesn't consider himself quite a Perl expert, he's fairly proficient at it.  And when I joined the company, and explained to him the wisdom of strict and warnings, he quickly agreed that their benefits outweigh any nuisance they cause, and started using them religiously in his own code.

But this particular script did not have strict and warnings as it was inherited legacy code, and adding them would have taken time away from finding the bug, which he was anxious to fix at the particular moment.

So the two of us narrowed it down to a place in the code where we had something like this:  (I'm paraphrasing here, not remembering the original exactly):

# See if we need to calculate refresh matrix, based on user options if ($qeneral_user_options =~ /c/) { # This branch was NOT being taken, contrary to expectations print "Options contains 'c'\n"; calculate_refresh_matrix(); } # Debugging code added to find bug else { print "Value of \$general_user_options = '$general_user_options'\n +"; }

and although the first branch was NOT being taken, the value of $general_user_options clearly contained the character 'c':

Value of $general_user_options = 'cde'

After struggling with it for more than half an hour, I finally tried editing it myself, (using vim, which I prefer over emacs), and the moment I used the '*' key to "bounce" to the next occurrence of the word "general_user_options" was when I realized, with a sinking feeling, what the problem was.  Someone had mistyped the flipping variable name... It should have been "general_user_options", but it was mistyped as "qeneral_user_options".  ... Ugh ...

Ordinarily neither of would have created that bug, because we both use strict and warnings, but of course we inherited the script (from someone who, I'm sure, just didn't need that kind of "hand-holding", and had, in fact, introduced a number of other scoping-related issues into the code).

So feel free to do whatever works for you.  If you've got too many warnings, and you don't want to see them, by all means turn them off if that's your style.  But I know how ridiculous it feels to miss something that miniscule, and waste a lot of time as a result, just because the usual safeguards weren't there from the beginning.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found