我希望@arr
直接包含城市名称。我打印时希望$arr[0]
为c1
。
代码有什么问题?
my $state="Illinois";
push @{$mstates{$state}}, "c1";
push @{$mstates{$state}}, "c2";
my @arr=$mstates{$state};
答案 0 :(得分:2)
也许你想要
my @arr=@{$mstates{$state}};
答案 1 :(得分:1)
好吧,
my @arr=@{$mstates{$state}};
即。,
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);
输出:
$VAR1 = [
'c1',
'c2'
];