find2perl
出自DebianWiki
使用過 perl 的人都懾服 perl 強大的威力。不僅只是文字處理與正規表示法的能力,在檔案系統的處理上也十分強大。[[[DebianPackages:perl-modules]] File::Find] 便是一個強大的模組,用戶可透過 find2perl 來將使用在 find 指令上的語法轉為 perl 指令,就像這樣
$ find2perl . -type f -name \*.c
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
[[$dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_]] &&
-f _ &&
/^.*\.c\z/s
&& print("$name\n");
}
在迅速的產生基本的程式碼與正規表示法後,便可以將欲處理檔案的程式碼寫在 wanted 函式中,或作其他的運用。更進階得資訊請參考 find2perl(1) 與 File::Find(3perl)。
![[Main Page]](/upload/4/49/Debian_taiwan_out.png)