我正在尝试收集我存储在哈希哈希中的值,但我对 perl 是如何做到这一点感到有点困惑。所以,我创建我的哈希哈希如下:
my %hash;
my @items;
#... some code missing here, generally I'm just populating the @items list
#with $currentitem items
while (<FILE>) { #read the file
($a, $b) = split(/\s+/,$_,-1);
$hash{$currentitem} => {$a => $b};
print $hash{$currentitem}{$a} . "\n";#this is a test and it works
}
上面的代码似乎工作。现在,重点是:我有一个数组@items,它保留了$currentitem 的值。我想做这样的事情:
@test = keys %hash{ $items[$num] };
这样我就可以获得特定项目的所有键/值对。我已经尝试了上面的代码行,以及
while ( ($key, $value) = each( $hash{$items[$num]} ) ) {
print "$key, $value\n";
}
我什至尝试按如下方式填充哈希:
$host{ "$currentcustomer" }{"$a"} => "$b";
根据我遇到的各种在线资源,这似乎更正确。但是,我仍然无法访问该哈希中的数据......有什么想法吗?