Closed p5pRT closed 19 years ago
(Sorry if this ends up as a duplicate. I sent it from a machine that is behind a firewall. I got a cc: copy\, but several hours later\, it is not yet listed in rt.perl.org. I am resending it.)
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;
test.pl:
#!/usr/local/bin/perl
$\="\n";
use lib '.';
use A; # DEBUG == 1
use B; # DEBUG == 0
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'; '???';
Thanks for any help\, -Colin.
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 rick@bort.ca
The RT System itself - Status changed from 'new' to 'open'
Thanks for pointing out my silly oversight.
-Colin.
On Sun\, Aug 21\, 2005 at 04:09:51PM -0400\, Rick Delaney wrote:
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.
Not a bug\, just an oversight.
rick@bort.ca - Status changed from 'open' to 'rejected'
Migrated from rt.perl.org#36960 (status was 'rejected')
Searchable as RT36960$