2013-01-16 25 views
0

所有Perl高手可以幫我瞭解的Perl代碼非perl的程序設計師

$a=18; 
$b=55; 
$c=16; 
$d=88; 
$mtk = { 
    'A'  => [$a, $b], 
    'M' => [$c, $d] 

    }; 

此塊是這本詞典保持焦炭和對以及如何訪問鍵和值 非常感謝

+3

閱讀有關[Perl數據結構(http://perldoc.perl.org/perldsc.html),應該可以幫助你以及。 –

回答

1

這是爲數組參考文獻作爲值的散列REF。這裏是低於橫向代碼:

for my $key (sort keys %$mtk) { 
    print "Current key is $key\n"; 
    for my $val (@{ $mtk->{$key} }) { 
     print "... and one of value is $val\n"; 
    } 
} 

輸出將是

Current key is A 
... and one of value is 18 
... and one of value is 55 
Current key is M 
... and one of value is 16 
... and one of value is 88