我喜欢File :: Find这个例子更好 - 它更便携,File :: Find可以做一些非常漂亮的东西。但是,我会提到一种可以在没有内置支持的情况下对其他命令有用的方法。
open F,'find . -type f | xargs grep -l "2000.*Created" | cut -c3-100 |' || die 'cannot execute';
while(<F>) { chomp ; push(@a,$_)}
注意在打开尾管(|
)......因为Perl会自动地做挂钩管你的所有的工作,这是很重要的。
open my $fh, '-|', 'find . -type f | xargs grep -l "2000.*Created" | cut -c3-100' || die 'cannot execute';
while(<$fh>) { chomp ; push(@a,$_)}
作为一个侧面说明,find | xargs
都将有一些问题,如果你有空格的文件名:
这也可以使用新的3参数的open写的。您可以解决,随着-print0
行动find
和-0
国旗xargs
:
find . -type f -print0 | xargs -0 -l "2000.*Created" | cut -c3-100
什么是'cut'命令末尾的目的是什么?去掉路径中的'“./”'?另外,File :: Finder只是File :: Find的一个包装,它是perl 5中的核心模块。 – TLP