in reply to replacing literals with constants

First of all, this ... is not a constant.

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.

Otherwise arguments are allowed, which is biting you here!

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

updates

  • s/code folding/constant folding/g