2011-03-31 33 views
0

我想@arr直接包含城市名稱。我打印時想要$arr[0]c1。 代碼有什麼問題?將數組存儲爲地圖值問題

my $state="Illinois"; 

push @{$mstates{$state}}, "c1"; 

push @{$mstates{$state}}, "c2"; 


my @arr=$mstates{$state}; 

回答

1

不喜歡它,

my @[email protected]{$mstates{$state}}; 

use strict; 
use warnings; 
use Data::Dumper; 
my $state="Illinois"; 
my %mstates; 
push @{$mstates{$state}}, "c1"; 
push @{$mstates{$state}}, "c2"; 
my @[email protected]{$mstates{$state}}; 
print Dumper(\@arr); 

輸出:

$VAR1 = [ 
      'c1', 
      'c2' 
     ];