The only way? Absolutely not. I know that adding print lines is the preferred method of debugging for some people, but in my mind an actual debugger is by far the best tool.

Advantages for print statements:

  1. Simple - don't need to learn anything new.
Advantages for a debugger:

  1. Powerful - stepping, (conditional) breakpoints, actions, watchpoints, etc.
  2. Versatile - examine any value -- or the result of any expression -- at any point.
  3. Informative - dump complicated data structures, view stack traces, etc.
When perl5.6.1 is released, it will include a tutorial on using the debugger, written by Richard Foley.

Editor's note: thanks to davorg and neophyte for the following information (combined into one answer for better reference):
If you have trouble using the built-in debugger (see perldoc perldebug), check out the tutorial Using the Perl Debugger on this site.


In reply to Re: Is adding print lines the only way to go to find computational error in a scrpt? by chipmunk
in thread Is adding print lines the only way to go to find computational error in a scrpt? by Elias

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.