Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: debug statements

by Fletch (Chancellor)
on Oct 03, 2006 at 18:00 UTC ( #576140=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: debug statements
Download Code
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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-08-30 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (292 votes), past polls