in reply to Re^2: defining constant in other package
in thread defining constant in other package

I am not sure what you mean by "constant folding." Perl ensures that "variables" marked as readonly cannot be used as l-values. I doubt that they are special in any other way.
  • Comment on Re^3: defining constant in other package

Replies are listed 'Best First'.
Re^4: defining constant in other package
by Jenda (Abbot) on Apr 25, 2012 at 08:16 UTC
    C:\Users\jenda>perl -MO=Deparse -e "print 1+2" print 3; -e syntax OK C:\Users\jenda>perl -MO=Deparse -e "use constant ONE => 1; print ONE+2 +" use constant ('ONE', 1); print 3; -e syntax OK C:\Users\jenda>perl -MO=Deparse -e "sub ONE () {1}; print ONE+2" sub ONE () { 1 } print 3; -e syntax OK C:\Users\jenda>perl -MO=Deparse -e "use Readonly; Readonly $ONE => 1; +print $ONE+2" use Readonly; Readonly $ONE, 1; print $ONE + 2; -e syntax OK

    See Constant folding. Apparently Readonly is not constant enough. So no constant folding, not unreachable code removal, ...

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.