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$..$/

In reply to Re: use warnings => Use of uninitialized value... by liverpole
in thread use warnings => Use of uninitialized value... by jeanluca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.