in reply to How to create a "CONSTANT"

which is an attempt to create a CONSTANT which looks like variable
use vars qw( $PIE ); *PIE = \"Warm Apple"; print "pie: $PIE\n";

You were pretty specific, so I'm assuming you were already aware of use constant PIE => "Warm Apple"; which results in a constant sub that can't be interpolated into strings (easily.)

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

Replies are listed 'Best First'.
Re: Re: How to create a "CONSTANT"
by Willard B. Trophy (Hermit) on Jun 07, 2003 at 15:22 UTC
    they're not that difficult to interpolate:
    use constant PIE => "Warm Apple"; print "The value of PIE is @{[ PIE ]}.\n";

    which gives:

    The value of PIE is Warm Apple.

    --
    bowling trophy thieves, die!

      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";

        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.";