现在提出不同意见。TMTWOTDI,正如@transistor1 在评论中所说。我还可以调用 Perl 的Whitituptitude 功能。如果你比模块更熟悉cp
,如果你不担心可移植性,如果你的程序可以承受启动一两个额外进程的性能损失(提示:它可能可以),Perl 可以很容易地将这些工具集成到您的程序中,使用任何可用的工具尽可能快地完成任务并没有错。mv
File::Copy
哎呀,有时在那些一次性任务中,Unix 实用程序是完成这项工作的正确工具,即使你知道如何在 Perl 中完成这项工作。
# I need log.err plus the next two oldest and the next two newest
# files in the current directory. Should I say
chomp(@f = qx[ls -t | grep -C2 log.err]);
# or
@e = sort { -M $a <=> -M $b } glob("*");
($i) = grep { $e[$_] eq 'log.err' } 0..$#e;
@f = @e[$i-2 .. $i+2];
# or
use Acme::OlderNewer::FileFinder;
@f = find_oldernewer_files(".", "log.err", -2, +2);
# ? Or suppose I want a list of all the *.pm files under all
# directories in @INC, and we lucked out so that nothing in @INC
# has any spaces or special characters.
# Is my script any less useful for saying
chomp(@f = `find @INC -name \\*.pm`);
# than
use File::Find;
find( sub { /\.pm$/ && push @f, $File::Find::name }, @INC );