in reply to Conditionally executing debugging code

Ah, but if you simply do something like:

BEGIN { eval "sub DEBUG() {" . ( $ENV{DEBUG} ? "1" : "0" ) . "}"; } # ... if( DEBUG ) { code here; } warn "Stuff" if DEBUG;
then, when debugging is not turned on, the conditional debug code is actually eliminated by the Perl optimizer so that it doesn't take up memory and the "if" conditional never even gets run!

Update: Yes, bbfu's idea is even better. (:

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
(bbfu) Re: (tye)Re: Conditionally executing debugging code
by bbfu (Curate) on May 26, 2001 at 07:01 UTC

    Wouldn't this work just as well (and be a little more pretty)?

    use constant DEBUG => ($ENV{DEBUG} ? 1 : 0); # ...

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.