next up previous contents
Next: Syntax Errors Up: Practical Perl Programming Previous: The Env Module

Debugging Perl

This chapter is about errors: how to find them and how to fix them. No programmer I've ever known of is able to consistently create perfect programs. So don't feel bad if you also have some problems you need to solve. I've spent many hours looking for a missing closing bracket or a misspelled variable name.

There are two different types of errors: syntax errors and logic errors. Syntax errors are made as you type your script into an editor. For example, you might not add a closing quote or might misspell a filename. Logic errors are more insidious and difficult to find. For example, you might place an assignment statement inside an if statement block that belongs outside the block. Or you might have a loop that runs from 0 to 100 when it should run from 10 to 100. Accidentally deleting the 1 or not entering it in the first place is very easy.

Syntax errors are usually easy to fix. The section "Common Syntax Errors" discusses some common syntax errors. You'll see how to decipher some of Perl's error messages.

Logic errors can be very hard to fix. They are discussed in the section "Logic Errors." While there is no magic wand to wave over a program that will identify logic errors, there are some tools that can help-like the debugger. A debugger is an environment that lets you execute your program line by line. This is also called single-stepping through your program. You can also display or modify the value of variables. The debugger is discussed in the section "Stepping Through Your Script."


 
next up previous contents
Next: Syntax Errors Up: Practical Perl Programming Previous: The Env Module
dave@cs.cf.ac.uk