On Fri, Aug 19, 2005 at 02:06:25PM -0700, Colin Meyer wrote:
> While playing with constant folding and compiler optimizations, I
> noticed something funny about B::Deparse.
> 
> It seems to strip the conditionals off of some statements, implying
> that they will always be run. However, they do not get run.
> 
> 
> Here's my test files:
> 
> A.pm:
>   package A;
>   use constant DEBUG => 1;
>   1;
> 
> B.pm:
>   package B;
>   use constant DEBUG => 0;
>   1;

This is the problem here.  When you run it with -MO=Deparse, Deparse
loads the core B.pm so your B.pm is never loaded.  If you change the
package name to "J", everything works fine.


> test.pl:
>   #!/usr/local/bin/perl
>   
>   $\="\n"; 
>   use lib '.';
>   use A; # DEBUG == 1
>   use B; # DEBUG == 0

Try both ways with this addition:

    BEGIN { warn "B loaded from $INC{'B.pm'}" }

>   use constant AorB  => A::DEBUG | B::DEBUG; # 1
>   use constant AandB => A::DEBUG & B::DEBUG; # 0
>   
>   print "A" if A::DEBUG;
>   print "B" if B::DEBUG;
>   if ( B::DEBUG ) { print "B" }
>   
>   print "AorB"  if AorB;
>   print "AandB" if AandB;
> 
> perl test.pl:
>   A
>   AorB
> 
> perl -MO=Deparse test.pl:
> 
>   test syntax OK
>   $\ = "\n";
>   use lib ('.');
>   use A;
>   use B;
>   use constant ('AorB', 1 | 0);
>   use constant ('AandB', 1 & 0);
>   print 'A';
>   print 'B';
>   do {
>       print 'B'
>   };
>   print 'AorB';
>   '???';
> 

-- 
Rick Delaney
[EMAIL PROTECTED]

Reply via email to