我正在使用 File::Find
遍历目录树的模块。找到特定文件后,我想停止搜索。我怎样才能做到这一点?
find (\$processFile, $mydir);
sub processFile() {
if ($_ =~ /target/) {
# How can I return from find here?
}
}
最佳答案
似乎你将不得不死:
eval {
find (\$processFile, $mydir);
};
if ( $@ ) {
if ( $@ =~ m/^found it/ ) {
# be happy
}
else ( $@ ) {
die $@;
}
}
else {
# be sad
}
sub processFile() {
if ($_ =~ /target/) {
die 'found it';
}
}
关于perl - 找到特定文件后,如何摆脱递归查找功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/381395/