Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: debugging /logging help

by dchetlin (Friar)
on Dec 07, 2000 at 10:23 UTC ( #45447=note: print w/replies, xml ) Need Help??

in reply to debugging /logging help

A brief comment on efficiency:

If you use constant subs instead of variables for toggling debugging, Perl is smart enough to compile them out of existence so when you go into production the debugging will have no adverse performance effects.

You can observe this in action using B::Deparse:

[~] $ perl -MO=Deparse -e'sub D(){0}print"foo"if D' sub D () { 0; } '???'; -e syntax OK [~] $ perl -MO=Deparse -e'sub D(){1}print"foo"if D' sub D () { 1; } print 'foo'; -e syntax OK

The `???' in the first example means that Perl has optimized out whatever used to be there. And you'll note the lack of a conditional in the second example, which was also optimized out. Perl is smart enough to realize that a subroutine with no parameters can be computed at compile time, and so replaces all calls to D() with its actual value (0 or 1 depending on the example). Then the peephole optimizer realizes that the print statements depend on the conditionals, and since the value of the conditionals is known, eliminates them and leaves either nothing, in the case of D() == 0, or just the bare print, in the case of D() == 1.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://45447]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-06-23 03:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.