There is a certain art to debugging that only experience
can teach. There are so many different places where things can
go wrong that it's impossible to remember which bug is most likely
to appear in a given scenario. If you have lived through the frustration
of tracking a bug for hours only to have someone look at your
program for three minutes and say, "Look, that minus sign
should be a multiplication sign!" you are much more likely
to find the bug the next time. There is no substitute for real-life
debugging.

Let's recap what you did learn in this chapter. You started
out by reading about syntax or compile-time errors. This class
of error involved a misplaced parenthesis, a missing quote, or
some other slip of the fingers while entering your program into
an editor. Syntax errors are found when Perl compiles your program
into an internal format prior to actually executing it. The only
way to track down a syntax error is to read the error messages
and look at your program.

Logic errors, on the other hand, can be harder to find. They involve
some logical flaw in your program. Using the index into an array
or specifying the wrong variable as a parameter to a function
both qualify as logic errors.

The first step to combating logic errors is to use the -w
command-line option. The -w
command tells Perl to display warning messages for various dangerous
coding practices.

The next step is to use the strict
pragma in your programs. This requires that you declare every
variable you use. Creating only local variables minimizes the
possibility of inadvertently changing the wrong variable or causing
side effects in your program.

If you still have logic errors after these two options have been
used, you might use the debugger. The debugger lets you single-step
through your program and print or modify variables. You can also
set breakpoints or actions, and you can interactively call any
function directly from the debugger command line.