in reply to defining constant in other package

No there isn't, but a constant is merely
sub Ro:Sham::Bo::DEBUG(){ !!1 } sub Ro:Sham::Bo::DEBUG(){ !!0 } package Ro:Sham::Bo; use constant DEBUG => !!$ENV{PERL_RO_SHAM_BO};

Replies are listed 'Best First'.
Re^2: defining constant in other package
by Anonymous Monk on Apr 24, 2012 at 14:31 UTC
    *sigh* if using the ENV option it should be
    package Ro:Sham::Bo; use constant DEBUG => !!$ENV{PERL_RO_SHAM_BO_DEBUG};
Re^2: defining constant in other package
by LanX (Saint) on Apr 24, 2012 at 14:41 UTC
    Well but even when putting a sub-declaration into a BEGIN block codefoldinmg isn't effected!

    > perl -MO=Deparse tst.pl sub BEGIN { sub MyPackg::DBG { 0; } } our $a = 1; package MyPackg; print 'DEBUGGING' if DBG(); # <-- oops print 'huhu'; tst.pl syntax OK

    OK forget it this works, thanks!

    BEGIN { sub MyPackg::Debug {!!0}; } our $a=1; package MyPackg; use constant DBG => MyPackg::Debug; print "DEBUGGING" if DBG; # won't be compiled print "huhu";

    > perl -MO=Deparse tst.pl sub BEGIN { sub MyPackg::Debug { 0; } } our $a = 1; package MyPackg; sub BEGIN { require constant; do { 'constant'->import('DBG', Debug()) }; } '???'; print 'huhu'; tst.pl syntax OK

    Cheers Rolf

      Perl wants a constant (subroutine) to have an empty prototype before it eliminates code guarded by it:

      BEGIN { sub MyPackg::DBG() { 0; } } our $a = 1; package MyPackg; print 'DEBUGGING' if DBG(); # <-- oops print 'huhu';

      gives this output:

      F:\>perl -MO=Deparse tmp.pl sub MyPackg::DBG () { 0 } sub BEGIN { } our $a = 1; package MyPackg; '???'; print 'huhu'; tmp.pl syntax OK
        Argh , thanks, already forgot about this.

        Cheers Rolf