Main Page | 最近更改 | 編輯本頁 | 頁面歷史

可列印版 | 免責聲明 | 隱私政策

未登入
登入 | 幫助
 

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)。

取自"http://wiki.debian.org.tw/index.php/find2perl"

本頁面已經被瀏覽4,002次。 這頁的最後修訂在 2006年12月21日 (星期四) 22:13。 本站的全部文本內容在GNU Free Documentation License 1.2之條款下提供。


[Main Page]
Main Page
社區
近期活動
最近更改
隨機頁面
幫助
贊助

編輯本頁
討論本頁
頁面歷史
鏈入頁面
鏈出更改

特殊頁面
錯誤報告