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

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!

Replies are listed 'Best First'.
Re: Re: Re: How to create a "CONSTANT"
by larsen (Parson) on Jun 07, 2003 at 15:50 UTC
    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.";