开发者

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'
        ];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜