Hi All,
I want to share my recent experience with debugging a code.

Task
I was processing about 500 files through a code that I had refactored extensively.

Problem
I noticed that while most of the files were parsed as expected, about 50 files were much smaller than the expected filesize. I tried rerunning the missing records through the parsing script and it produced the expected result! This was driving me crazy.

Solution
I then used a Perl debugging tool on the original file and ran the script step by step to see why I am getting a smaller file. The culprit was this line in some 500 lines of code:
if( $variable > $certain_value) { exit; }
While this works for most of the files where this condition is not satisfied, certain files do meet this criteria and hence the script exits prematurely!
When I changed this to skip to the next record, it worked like a charm!
if( $variable > $certain_value) { next RECORD; }
Lessons Learned
Even if it takes time to run a script line by line using the debugger, spend this time to save your sanity!

In reply to How a baisc debugging effort restored my sanity! by umasuresh

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.