Storing array as map values problem
I want @arr
to directly contain the cities name. I want $arr[0]
to be c1
when 开发者_运维问答I print.
What is wrong with the code?
my $state="Illinois";
push @{$mstates{$state}}, "c1";
push @{$mstates{$state}}, "c2";
my @arr=$mstates{$state};
maybe you wanted
my @arr=@{$mstates{$state}};
Do it like,
my @arr=@{$mstates{$state}};
ie.,
use strict;
use warnings;
use Data::Dumper;
my $state="Illinois";
my %mstates;
push @{$mstates{$state}}, "c1";
push @{$mstates{$state}}, "c2";
my @arr=@{$mstates{$state}};
print Dumper(\@arr);
output:
$VAR1 = [
'c1',
'c2'
];
精彩评论