傳參數給 File::Find::find 的 wanted 函數

[華語, cmn-Hant-TW]

有用到順便記一下,參考這個網頁的討論,應該這樣寫即可

File::Find::find( {wanted => sub { wanted($arg) }}, $dir);
sub wanted {
  my ( $arg ) = $_;
  ...
}

$arg 即為要傳的參數,$dir 是搜尋目錄。當然參數要傳 reference 也是可以的,像是傳陣列就把參數改成 \@array 之類的即可,丟 reference 的原因是 wanted 函數不會回傳東西,要把處理後東西挖出來就得用這個方法。

Leave a Reply

Your email address will not be published. Required fields are marked *