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

Readonly can be used for constant folding?

Cheers Rolf

  • Comment on Re^2: defining constant in other package

Replies are listed 'Best First'.
Re^3: defining constant in other package
by BillKSmith (Monsignor) on Apr 24, 2012 at 23:25 UTC
    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.
      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.