加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

数组 – 在Perl中的哈希中迭代哈希数组

发布时间:2020-12-15 23:29:00 所属栏目:大数据 来源:网络整理
导读:我在哈希中有一个哈希数组,如下所示: $VAR1 = { 'file' = [ { 'pathname' = './out.log','size' = '51','name' = 'out.log','time' = '1345799296' },{ 'pathname' = './test.pl','size' = '2431','name' = 'test.pl','time' = '1346080709' },{ 'pathname'
我在哈希中有一个哈希数组,如下所示:

$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";
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读