I'm working with a HoH right now in which each inner hash has the same keys. It occurred to me that perl has no const type. After poking through some code that my co-workers wrote, I realized the solution to creating a constant in perl is to write a subroutine that returns the string you want.
#!/usr/bin/perl use strict; my %foo; my $key; $foo{&KEY_NAME}="jon"; $foo{&KEY_OCCUPATION}="just another perl hacker"; sub KEY_NAME { return "Name"; } sub KEY_OCCUPATION { return "Occupation"; } foreach $key(keys %foo) { print "$key : " . $foo{$key} . "\n"; }

Replies are listed 'Best First'.
RE: Constants and perl
by chromatic (Archbishop) on Jun 15, 2000 at 02:56 UTC
    There's also a constant pragma:
    use constant PI => 4 * atan2 1, 1; use constant DEBUGGING => 0; print "This line does nothing" unless DEBUGGING;
    (shamelessly ripped from the perldoc page :)
RE: Constants and perl
by btrott (Parson) on Jun 15, 2000 at 03:03 UTC
    There's also Const, which works differently than what you've got here (and differently than the constant pragma). Instead of using subroutines, it uses tied variables. This lets you use the constants as hash keys directly, which is nice.

    Use it like this: (taken from the manpage)

    use Const; const my $SCALAR1 => 10 ;
    There's a post on perl5-porters about constant/readonly values: Re: Proposed pragma: readonly - summary. I believe most of these are just proposals, but it's rather interesting.