Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: debug statements

by Fletch (Bishop)
on Oct 03, 2006 at 18:00 UTC ( [id://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.

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found