There are a couple of ways to debug this kind of problem. You can alter the code by littering the landscape with print statements. This has the advantage of making you look at the code to determine where you should be dropping your "DEBUG Reached line NNN, variable xxx=$xxx<<<<\n" statements. Quite often when I use this style of debugging I would run across my logic error in the process. Then I had to go back and remove my previous debugging statements. When I initially was introduced to Perl, some mumble years ago, that is how I did debugging.

After a few months I discovered the Perl Debugger --  perl -d; I have not gone back to print statements, except as a last resort (and usually in CGI coding).

I step through the code until the code takes off in a different direction from what I expected. I look at the variables involved in the control construct that surprised me. I track back to where the erroneous value appeared, fix my bug and go on.

Whether one method or the other is 'better' is not something that I can really say. I get a better feel for the logic by watching the way the Program flows as I step from point to point in the execution. I know other programmers who can parse the logic-flow as they read the code, and decide on where they want to insert debugging statements based on their mental map of the logic. It all depends on what you are comfortable with.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: Can someone tell me why this hangs?? by Old_Gray_Bear
in thread Can someone tell me why this hangs?? by monty77

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.