#!perl use strict; use warnings; my $state_capital_of; $state_capital_of->{'Alabama'} = 'Montgomery'; $state_capital_of->{'Alaska'} = 'Juneau'; $state_capital_of->{'Arizona'} = 'Phoenix'; $state_capital_of->{'Arkansas'} = 'Little Rock'; $state_capital_of->{'California'} = 'Sacramento'; print "$state_capital_of->{'Alabama'}\n"; print "$state_capital_of->{'Alaska'}\n"; print "$state_capital_of->{'Arizona'}\n"; print "$state_capital_of->{'Arkansas'}\n"; my $state = 'California'; print "$state_capital_of->{$state}\n" if exists $state_capital_of->{$state};
This prints
Montgomery Juneau Phoenix Little Rock Sacramento
In reply to Re: Access the Keys of a Hash Reference Without a For Loop
by Jim
in thread Access the Keys of a Hash Reference Without a For Loop
by Dru
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |