Perl中的数组哈希

时间:2017-09-16 20:39:00

标签: perl

我正在尝试创建一个数组哈希。如何访问/打印整个阵列?这是代码:

 my %data;    
 my @row = ("My", "Name", "is", "Anthony", "Gonzalves");
 print "@row";
 $data{'First'} = \@row;
 print "@data{'First'}"; 

上述代码的输出是: 我的名字是Anthony GonzalvesARRAY(0x7fa1a5831dc8)。

1 个答案:

答案 0 :(得分:0)

您应该使用@{}来访问数组的引用:

%HoA=(
    flintstones =>["fred","barney"],
);

$HoA{teletubbies}=["tinky winky","dipsy","laa-laa","po"];

for $family (keys %HoA){
    print "$family: @{$HoA{$family}}\n";
}

输出结果为:

simpsons: homer Marge bart
teletubbies: tinky winky dipsy laa-laa po