in reply to Re: inlined DEBUG constant versus $DEBUG
in thread inlined DEBUG constant versus $DEBUG

I never claimed significant speed improvement. What I had in mind is debugging thru the perl debugger. In that case the print statement becomes noise. I don't want anything to print, I even don't want to bother to go thru the statement that contains the print. Oddly, with use constant DEBUG => 0 I indeed step thru the statement that contains the print:  print "whatever\n" if DEBUG.
Worse I also step thru one line of constant.pm!

With sub DEBUG() { 0 } I still step thru the statement that contains the print. When debugging one goes from one nextstate opcode to the next. We see that consecutive nextstate statements are not fusionned as I expected them to be:

Both oneliners give me the same tree: perl -e ' sub DEBUG() { 0 } ; use O qw( Concise -exec); print "toto" if DEBUG; print "toto" if DEBUG'

perl -e ' use constant DEBUG =>0; use O qw( Concise -exec); print "tot +o" if DEBUG; print "toto" if DEBUG' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <;> nextstate(main 1 -e:1) v 4 <@> leave[t1] vKP/REFC

I don't understand how I get thru one line of constant.pm when debugging using constants!!!

I tested using perl 5.6.1

-- stefp

Replies are listed 'Best First'.
Re: Re: Re: inlined DEBUG constant versus $DEBUG
by derby (Abbot) on Sep 19, 2001 at 19:14 UTC
    stefp,

    That's why I tend to favor 'n' over 's'. However, when I debug code that contains

    sub DEBUG () { 0 }
    I still step through the DEBUG subroutine. Which is what I would expect while debugging. Try:

    perl -de 'use constant DEBUG =>0; use O qw( Concise -exec); print "toto" if DEBUG; print "toto" if DEBUG'

    perl -de 'sub DEBUG() { 0 }; use O qw( Concise -exec); print "toto" if DEBUG; print "toto" if DEBUG'

    -derby