基本上我要做的就是浏览目录并对所有文件执行操作,在本例中为子searchForErrors.这个子工作.到目前为止我所拥有的是:
sub proccessFiles{
my $path = $ARGV[2];
opendir(DIR, $path) or die "Unable to open $path: $!";
my @files = readdir(DIR);
@files = map{$path . '/' . $_ } @files;
closedir(DIR);
for (@files){
if(-d $_){
process_files($_);
}
else{
searchForErrors;
}
}
}
proccessFiles($path);
Run Code Online (Sandbox Code Playgroud)
任何帮助/建议都会很棒.而且,我是Perl的新手,所以解释越多越好.谢谢!
TLP*_*TLP 10
您应该使用File::Find模块而不是尝试重新发明轮子:
use strict;
use warnings;
use File::Find;
my @files;
my $start_dir = "somedir"; # top level dir to search
find(
sub { push @files, $File::Find::name unless -d; },
$start_dir
);
for my $file (@files) {
searchForErrors($file);
}
Run Code Online (Sandbox Code Playgroud)
您当前代码的一个问题是您在递归搜索中包含.和..目录,这无疑会导致deep recursion错误.