next up previous contents
Next: Using the -w Command-Line Up: Debugging Perl Previous: Common Syntax Errors

Logic Errors

These are the programming problems -- sometimes called bugs -- that you can stare at for hours without having a clue about why your script doesn't work. If you find yourself in this position, take a walk or eat some chocolate. In other words, take a break from staring at the computer screen. You can also find another programmer to walk through the code with you. Quite often while explaining the code to someone else, the problem becomes obvious.

Besides these two options, you can do the following:

Each of these options is discussed in separate sections later.

As a general rule, when debugging logic errors it helps to break complex expressions and statements into simpler ones: the simpler, the better. Use temporary variables if you need to. If you use the ++ or - operators inside function calls or complex expressions, don't. Move the decrement or increment operation to a separate line. After the program is debugged, you can always recombine the simple statements into complex ones.

Tip One of the most common logic problem is using the assignment operator (=) when you should use the equality operator (==). If you are creating a conditional expression, you'll almost always use the equality operator (==).



 
next up previous contents
Next: Using the -w Command-Line Up: Debugging Perl Previous: Common Syntax Errors
dave@cs.cf.ac.uk