in reply to debug statements

If you use a constant sub (declared with the constant pragma) then the code should get optimized away at compile time.

use constant DEBUG => 0; ## ... print "DEBUG: JINKIES!\n" if DEBUG();

There's also an evil live comments module (specially formatted text in comments is printed as debugging output) that someone wrote but the name of which escapes me at the moment . . .

Update: Smart::Comments, that was it. Of course that gets the usual "source filters are teh debil" warnings.

Replies are listed 'Best First'.
Re^2: debug statements
by djp (Hermit) on Oct 04, 2006 at 03:43 UTC
    Source filters are only evil if you invoke them, the beauty of smart comments is that normally they're just comments. Just leave 'use Smart::Comments' out of your code, then to invoke the smart comments (and the source filter), invoke your script via:
    perl -MSmart::Comments myscript.pl
    or for finer control:
    perl -MSmart::Comments='####' myscript.pl
    See Smart::Comments for details. This way you have zero overhead except when debugging. I'm surprised this simple technique isn't mentioned in the documentation.
Re^2: debug statements
by monarch (Priest) on Oct 04, 2006 at 15:29 UTC
    I have to say I really like this; I've been using Perl for a while but hadn't thought about optimising debug statements away at compile time using this trick. Thanks!
      Well it's not really optimizing debug statements away at compile time, it's optionally compiling them in at compile time. Same difference I suppose.