in reply to defining constant in other package

As a side issue, I would always prefer to see Readonly rather than constant. The resulting structure is syntactically a variable rather than a function. The biggest advantage is that it interpolates in a string the same as any other variable.

Replies are listed 'Best First'.
Re^2: defining constant in other package
by LanX (Saint) on Apr 24, 2012 at 22:44 UTC
    Readonly can be used for constant folding?

    Cheers Rolf

      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.