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

如何在Perl中使用File :: Find?

发布时间:2020-12-15 21:19:58 所属栏目:大数据 来源:网络整理
导读:我有点困惑File :: Find文档…等于$ find my_dir -maxdepth 2 -name“* .txt”? 解决方法 就个人而言,我更喜欢 File::Find::Rule ,因为这不需要你创建回调例程。 use strict;use Data::Dumper;use File::Find::Rule;my $dir = shift;my $level = shift //
我有点困惑File :: Find文档…等于$ find my_dir -maxdepth 2 -name“* .txt”?

解决方法

就个人而言,我更喜欢 File::Find::Rule,因为这不需要你创建回调例程。
use strict;
use Data::Dumper;
use File::Find::Rule;

my $dir = shift;
my $level = shift // 2;

my @files = File::Find::Rule->file()
                            ->name("*.txt")
                            ->maxdepth($level)
                            ->in($dir);

print Dumper(@files);

或者创建一个迭代器:

my $ffr_obj = File::Find::Rule->file()
                              ->name("*.txt")
                              ->maxdepth($level)
                              ->start($dir);

while (my $file = $ffr_obj->match())
{
    print "$filen"
}

(编辑:李大同)

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

    推荐文章
      热点阅读