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?? |
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):
and although the first branch was NOT being taken, the value of $general_user_options clearly contained the character 'c':
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$..$/
In Section
Seekers of Perl Wisdom
|
|