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
In reply to Optimize debugging subs by danb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |