For constant folding (optimization at compile time) to happen, you need a a prototype of () , to make sure the result doesn't depend on input.
The following demos with B::Deparse will demonstrate what is happening
C:\tmp>perl -MO=Deparse,-p -e"sub ten {10}; print ten() - 1" sub ten { 10; } print((ten() - 1)); # <-- +- call no args -e syntax OK C:\tmp>perl -MO=Deparse,-p -e"sub ten {10}; print ten - 1" sub ten { 10; } print(ten((-1))); # <-- +- call with args -e syntax OK C:\tmp>perl -MO=Deparse,-p -e"sub ten() {10}; print ten - 1" sub ten () { 10; } print(9); # <-- +- constant folding -e syntax OK C:\tmp>perl -MO=Deparse,-p -e"sub ten {10}; 9 .. ten - 1" sub ten { 10; } (9 .. ten((-1))); # <-- +- not what you wanted -e syntax OK C:\tmp>
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: replacing literals with constants (empty prototype needed)
by LanX
in thread replacing literals with constants
by hexcoder
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |