in reply to How can I declare constants?

Beside the already mentioned constant pragma, there's also the Readonly module. The advantage of Readonly is that you can mark interpolatable variable readonly (that is, constant), instead of using subroutines.
use Readonly; Readonly my $foo => "bar"; $foo .= "baz"; __END__ Modification of a read-only value attempted at ...
Perl --((8:>*

Replies are listed 'Best First'.
Re^2: How can I declare constants?
by sauoq (Abbot) on Oct 06, 2005 at 04:16 UTC

    Or just do it the old-fashioned way if all you need is constant scalars and you don't care if they are globals. Since, I find I often want my constants to be global and I rarely need a constant array or hash, this works very well for me. And on those rare occassions when I do have a need for a constant array (or hash), I never need to interpolate them... so use constant generally works just fine in those cases.

    *PI = \3.14159; *SLOGAN = \q(Don't tread on me!);
    -sauoq
    "My two cents aren't worth a dime.";