Perl递归遍历指定文件下的文件

#!/usr/bin/perl -w
use strict;
#use autodie;
#use File::HomeDir; #第三方模块,不管在什么操作系统上都能进入指定用户的主目录

my $parentDir = 'F:webperlperl programlittleCamp';
my $partInfo = '.+.pl$'; #正则表达

&search_file($parentDir, $partInfo);

sub search_file
{
    my ($dir, $partInfo) = @_;
    #print $partInfo, "
";
    opendir my $dh, $dir or die "Cannot open dir $dir
";
    my @files = readdir $dh; #标量上下文和列表上下文
    foreach my $file (@files)
    {
        my $filePath = "$dir/$file";
        if(($file =~ m#$partInfo#i) and (-f $filePath)) #-f 判断是否是文件
        {
            print "$filePath
";
        }
        if((-d $filePath) and ($file ne '.') and ($file ne '..')) #-d判断是否是目录
        {
            &search_file($filePath, $partInfo);
        }
    }
}
system 'pause';

原文地址:https://www.cnblogs.com/v-BigdoG-v/p/7398606.html