Zed Lopez


File::Find is a very nifty perl module on CPAN for finding files by whatever criteria and operating on them. Its docs say:

See also the script pfind on CPAN for a nice application of this module.

which becomes a little cryptic when you see there is no pfind on CPAN. But here’s pfind and it’s a pretty nifty tool to have alongside ack for replacing complicated find/grep pipelines.


pfind – find-or-grep-like utility with Perl syntax


To lowercase only the files names of which contain “blah”, do

pfind . /blah/ ‘$_ = lc’

To lowercase only the files which contain “blah” inside, do

pfind . “=~ /blah/” ‘$_ = lc’

To do recursive “grep foo bar*” in UTF-8 files, do

pfind -utf8 -alllines . ‘/^bar/’ ‘=~ /foo/’ prt_line



pfind debug] [-nosubdir] [-bin] [-bak=suffix] [-alllines] [-utf8] [-vars] [-nochdir] [-opts=OPTIONS] [- startdir rule1 rule2 …

Rules: filters and actions

Rules are perl statements to execute. Statements starting with “-”, “/”, “$dir =~”, “$dir !~”, “$name =~”, “$name !~”, or “!” are considered filters, a file will be discarded unless the statement returns true.

Statements starting with “=~” (possibly negated by prepending “!”) are filters applied to the contents of the file. The rest is executed as is.

Rules are executed in the directory of the file.