【发布时间】:2014-03-02 04:55:04
【问题描述】:
我有一个哈希数组,看起来像这样:
$var = {
'items' => [
{
'name' => 'name1',
'type' => 'type1',
'width' => 'width1',
},
{
'name' => 'name2',
'type' => 'type2',
'width' => 'width2',
},
{
'name' => 'name3',
'type' => 'type3',
'width' => 'width3',
}
]
};
我编写了以下代码来从文件中获取值。
my @members = ("name" => $name,
"type" => $type,
"width" => $width);
$rec->{$items} = [ @members ];
push @var, $rec;
我不确定如何从此数据结构中检索值。
我在Iterate through Array of Hashes in a Hash in Perl 中看到了解决方案。 但我不明白。我不确定他们在代码中提到的 $filelist 是什么。
foreach my $file (@{ $filelist{file} }) {
print "path: $file->{pathname}; size: $file->{size}; ...\n";
}
我是 perl 新手,请在回复中提供详细信息。
【问题讨论】:
-
$var是对散列的引用,该散列的元素之一(迄今为止唯一的一个)是items数组。除了items之外,您还需要在该哈希中包含任何其他元素吗?