我喜歡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