danb has asked for the wisdom of the Perl Monks concerning the following question:
You can see the call gets optimized away in the Deparse output:use constant ENABLE_DEBUG => 0; sub debug { print $_[0]; } debug 'test' if ENABLE_DEBUG;
However, the more elegant equivalent...use constant ('ENABLE_DEBUG', 0); sub debug { print $_[0]; } '???';
...does not get optimized away:use constant ENABLE_DEBUG => 0; sub debug { print $_[0] if ENABLE_DEBUG(); } debug 'test';
Update 1: diotalevi convinced me to use constant. Update 2: I stumbled on Smart::Comments, which is very interesting, but I don't know if it could be made to work with Log::Log4perl. Plus, it's a source filter (take that as you will).use constant ('ENABLE_DEBUG', 0); sub debug { 0; } debug 'test';
--Dan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Optimize debugging subs
by diotalevi (Canon) on Apr 05, 2006 at 04:21 UTC | |
|
Re: Optimize debugging subs
by ikegami (Patriarch) on Apr 05, 2006 at 05:13 UTC | |
|
Re: Optimize debugging subs
by roboticus (Chancellor) on Apr 05, 2006 at 03:29 UTC | |
by danb (Friar) on Apr 05, 2006 at 04:24 UTC | |
|
Re: Optimize debugging subs
by Anonymous Monk on Apr 05, 2006 at 03:34 UTC | |
by danb (Friar) on Apr 05, 2006 at 04:20 UTC | |
by ikegami (Patriarch) on Apr 05, 2006 at 05:07 UTC | |
by danb (Friar) on Apr 05, 2006 at 06:10 UTC | |
by ikegami (Patriarch) on Apr 05, 2006 at 14:22 UTC |