in reply to When my script doesn't work, I ...
- make sure its really a bug (agreed Vornitch) - I even have a name for this: "expectation errors"
- sprinkle printf STDERR liberally around the suspected problem spot. In my own code, I only use STDERR for debugging so it makes it very easy for me to find my debugging statements and comment them out. For other peoples code, I sometimes add #DEBUG before or at the end of a line so I can find all of my debugging statements easily (I tend to forget where I put them).
- for wierd compile time bugs, I use ___END__. Perl sometimes notices a problem loooong after the actual bad syntax, so I put __END__ at a place where the file compiles without a problem. Then I move it downward in the file until Perl starts complaining. The true location of the bad syntax is somewhere near that point.
- look for stray key strokes -- sometimes if the Alt key gets stuck alt-fs (file-save) turns into "fs" in some odd place in the current document. I've seen some REALLY wierd bugs suddenly appear that way.
- write a test suite to either (a) check to see which values cause problems (b) to pummel subroutine calls with data and verify they are working correctly
For serious debugging problems the test suite is really the way to go.
The only time I've ever used a debugger was when I had to solve problems at the C level of Perl. But often even that isn't necessary because there are Perl routines that will dump out the guts of the C data structure. So even internals can often be tested using good old Test::More and a few print STDERR statements.
In C/C++ you DO sometimes need a debugger because simply putting in a print statement can end up changing where data gets put and make a memory error go away. Perl doesn't have the same issues though.
|Replies are listed 'Best First'.|
Re^2: When my script doesn't work, I ...
by Anonymous Monk on Oct 05, 2012 at 06:03 UTC
In Section Past Polls