Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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.

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
    or for finer control:
    perl -MSmart::Comments='####'
    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?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2019-11-15 08:26 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (80 votes). Check out past polls.