A junior wrote some code like this:
use strict; use warnings; our $a = "something"; if($a eq "taste") { print "\nNot equals"; } elsif($a eq m/ERROR/) { print "\nNot matches regex"; }

I wasted 15 mins trying to figure out what was wrong at line 6, because PERL told me to look there:

Use of uninitialized value $_ in pattern match (m//) at wtf.pl line 6.

Yes, I read that you should look around the block where PERL issues a warning message and not usually at the line number itself, but do understand that in real life the code which resulted in this error message was not so tiny as I have posted, neither were the number of conditions and/or branches... so visual inspection is not always very reliable neither productive..

Any suggestions on how to locate the snippet in error next time I face a similar error ?

For those still wondering, an 'eq' should be '=~'.. oh well..


In reply to Tracking down the line in error or warning by PoorLuzer

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.