And*_*dyH 4 arrays perl hash loops
我在哈希中有一个哈希数组,如下所示:
$VAR1 = {
'file' => [
{
'pathname' => './out.log',
'size' => '51',
'name' => 'out.log',
'time' => '1345799296'
},
{
'pathname' => './test.pl',
'size' => '2431',
'name' => 'test.pl',
'time' => '1346080709'
},
{
'pathname' => './foo/bat.txt',
'size' => '24',
'name' => 'bat.txt',
'time' => '1345708287'
},
{
'pathname' => './foo/out.log',
'size' => '75',
'name' => 'out.log',
'time' => '1346063384'
}
]
};
Run Code Online (Sandbox Code Playgroud)
如何在循环中迭代这些"文件条目"并访问其值?是否更容易复制,my @array = @{ $filelist{file} };所以我只有一个哈希数组?
Mor*_*kus 15
无需复制:
foreach my $file (@{ $filelist{file} }) {
print "path: $file->{pathname}; size: $file->{size}; ...\n";
}
Run Code Online (Sandbox Code Playgroud)