可以像这样使用Perl的File :: Find模块:
find( \&wanted, @directories);
Run Code Online (Sandbox Code Playgroud)
我们如何在wanted函数中添加参数?
例如,我想在/tmp从每个文件中提取一些信息时遍历文件,结果应存储到不同的目录中.输出目录应作为参数给出.
mir*_*rod 10
你使用一个闭包:
use File::Copy;
my $outdir= "/home/me/saved_from_tmp";
find( sub { copy_to( $outdir, $_); }, '/tmp');
sub copy_to
{ my( $destination_dir, $file)= @_;
copy $file, "$destination_dir/$file"
or die "could not copy '$file' to '$destination_dir/$file': $!";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2449 次 |
| 最近记录: |