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:
- Simple - don't need to learn anything new.
Advantages for a debugger:
- Powerful - stepping, (conditional) breakpoints, actions, watchpoints, etc.
- Versatile - examine any value -- or the result of any expression -- at any point.
- 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.