develooper Front page | perl.perl5.porters | Postings from November 2003

constand optimization

Thread Next
From:
david
Date:
November 4, 2003 01:33
Subject:
constand optimization
Message ID:
20031103225856.59324.qmail@onion.perl.org
i am under the impression that Perl's constant folding optimization pairing 
with inlining a constand function should optimize away a certain construct. 
that's doesn't seem to be the case on the following examples. can someone 
explain why?

[panda]# perl -MO=Deparse -e 'use constant f=>0; if(f){print "hi"}'
use constant ('f', 0);
'???';
-e syntax OK
[panda]#

that looks fine. now:

[panda]# perl -MO=Deparse -e 'sub f(){0} if(f){print "hi"}'
'???';
-e syntax OK
[panda]#

fine again. however why shouldn't the following:

[panda]# perl -MO=Deparse -e 'sub f(){my $i=0; $i} if(f){print "hi"}'
sub f () {
    my $i = 0;
    $i;
}
if (f) {
    print 'hi';
}
-e syntax OK
[panda]#

or the following:

[panda]# perl -MO=Deparse -e 'BEGIN{my $i=0; sub f(){$i}} if(f){print "hi"}'
sub BEGIN {
    my $i = 0;;
    sub f () {
        $i;
    }

}
if (f) {
    print 'hi';
}
-e syntax OK
[panda]#

am i missing something? btw, why is there double ';' after my $i=0?

thanks!
david

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About