in reply to removing debugging code at compile time ?

here's something i just came up with. if you have the module My::Module, it will check for MY_MODULE_DEBUG.
use constant DEBUG => do { (my $p = __PACKAGE__ ) =~ tr/a-z:/A-Z_/s; $ENV{ $p . '_DEBUG' } || 0; };

Replies are listed 'Best First'.
Re: how do you check if it's compiled away?
by GrandFather (Saint) on Aug 17, 2007 at 04:05 UTC

    with the minor gotcha that 'Apple::Peeler' becomes 'APLE_PELER_DEBUG'.


    DWIM is Perl's answer to Gödel
      darn, i forgot about that. i had originally had a `uc` i was trying to optimize away. so the working version is:
      use constant DEBUG => do { (my $p = uc __PACKAGE__ ) =~ tr/:/_/s; $ENV{ $p . '_DEBUG' } || 0; };
        And all for nothing, because I believe in most (I dare not say "all") systems, environment variables (and %ENV) are case insensitive.

        Well, it definitely doesn't hurt.