Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
P is for Practical

Re: When my script doesn't work, I ...

by ELISHEVA (Prior)
on Oct 04, 2012 at 17:24 UTC ( #997264=note: print w/ replies, xml ) Need Help??

in reply to When my script doesn't work, I ...

  1. make sure its really a bug (agreed Vornitch) - I even have a name for this: "expectation errors"
  2. 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).
  3. 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.
  4. 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.
  5. 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.

Comment on Re: When my script doesn't work, I ...
Download Code
Re^2: When my script doesn't work, I ...
by Anonymous Monk on Oct 05, 2012 at 06:03 UTC

    The "__END__" point becomes hopeless when it appears before definitions of functions being used before (__END__). At this point, instead, a die is introduced.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997264]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-04-19 11:36 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (480 votes), past polls