I have a Perl file code state.pl where I am trying to retrieve full name of State based on State code from Hash of Arrays. Following is the code:
my $all_state_details = {
IN => [
[
"AP",
"Andhra Pradesh"
],
[
"AN",
"Andaman and Nicobar Islands"
],
[
"AR",
"Arunachal Pradesh"
],
],
US => [
[
"AL",
"Alabama"
],
[
"AK",
"Alaska"
],
[
"AS",
"American Samoa"
],
],
};
my $state = 'AN';
my $country = 'IN';
my @states = $all_state_details->{$country};
my @state_name = grep { $_->[0] eq $state } @states;
print @state_name;
When I run the script, I get the blank output
I want the output as just:
Andaman and Nicobar Islands