in reply to Best practice for handling subroutines that are conditionally loaded?

An idiom I learned from an ingy module, almost certainly Pegex, is:
use constant DEBUG => $ENV{MY_DEBUG}; # ... DEBUG and print "something\n";
The benefit is that constant-folding means that if it's not in debug mode, the Perl interpreter will simply optimise the debugging code out entirely.
  • Comment on Re: Best practice for handling subroutines that are conditionally loaded?
  • Download Code

Replies are listed 'Best First'.
Re^2: Best practice for handling subroutines that are conditionally loaded?
by Bod (Parson) on Mar 09, 2024 at 22:06 UTC

    That's a beautifully elegant solution...
    ...and the interpreter optimisation is a big bonus :)