in reply to Easy, elemental, but cool debug trick.

Well, you might want to consider doing it with the constant pragma. use constant DEBUG => 1; I tend to alternate between that and simply testing $^W: print qq(\$foo is "$foo"\n) if $^W; IMO, -w should never be enabled in production code (except insofar as you think you might forget to reenable it when you start development again!) so this works well.

Replies are listed 'Best First'.
Re: Easy, elemental, but cool debug trick.
by Anonymous Monk on May 31, 2000 at 06:43 UTC
    2 comments. I use: $debug = 20; print "debug info here\n" if $debug > 5 print "even more info here\n" if $debug > 10 etc. which lets me turn on and off levels of debug during the process (e.g. subroutines can dump details or just announce their presence as they get 'better' throughout the scripting). I try to write these sorts of debug stmts at the beginning and leave them in (often for years ;-) as experience shows I'll need them later and often need to turn them back on or bump the levels back up as things change. The other thing I just saw was somebody wrote all there constant comparisons: if ( 6 == $value ) { ... claiming that this "catches" the missing "=" problem at compile time (can't do 6 = $value) w/o the -w. Not sure I believe its a good thing (ugly for one, reads wrong) and not sure '6' shouldn't be $value_if_this sort of constant somewhere (in most cases) but the fellow is very accomplished programmer so take it for what you will. a