Reputation: 945
If I define a Perl hash as a constant, like:
use constant SITES => {foo => 1, bar => 2};
how do I retrieve the values for foo and bar? $SITES{foo} does not work.
Upvotes: 2
Views: 583
Reputation: 541
As it is a constant so no need to use $ infront of the variable and value is hash reference not just hash so HASH{'key'} would not work.
use instead SITE->{'foo'}
Upvotes: 0
Reputation: 29772
my $site_foo = SITES->{foo};
my $site_bar = SITES->{bar};
SITES
is essentially a subroutine that returns a hash reference.
Upvotes: 7