我在哈希中有一个哈希数组,如下所示:
$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','time' => '1346063384' } ] };
如何在循环中迭代这些“文件条目”并访问其值?是否更容易复制我的@array = @ {$filelist {file}};所以我只有一系列哈希?
解决方法
无需复制:
foreach my $file (@{ $filelist{file} }) { print "path: $file->{pathname}; size: $file->{size}; ...\n"; }