in reply to Re: Re: How to create a "CONSTANT"
in thread How to create a "CONSTANT"

The reference-dereference trick works even with scalars (which is clearer, IMHO: we're a printing a scalar, not a sui generis array):
print "The value of PIE is ${ \PIE }.\n";

Replies are listed 'Best First'.
Re: Re: Re: Re: How to create a "CONSTANT"
by sauoq (Abbot) on Jun 07, 2003 at 19:00 UTC

    Consider, for the heck of it, this:

    use constant TWO => 2; $x = TWO; print "$x ${\TWO}\n";
    Then someone comes along and changes the constant...
    use constant TWO => qw( one three ); $x = TWO; print "$x ${\TWO}\n";
    Oops. So, if you are going to do that defensively you should be a little more explicit...
    use constant TWO => qw( one three ); $x = TWO; print "$x ${\scalar TWO}\n";
    Sure, anyone who goes around changing constants should expect fire and brimstone to rain down on him... but it still happens. :-)

    -sauoq
    "My two cents aren't worth a dime.";