[Pdx-pm] recursive IO::Dir alternatives

Tom Keller kellert at ohsu.edu
Thu Feb 18 13:09:05 PST 2010

Summary for modules to traverse a directory tree:
0. q(don't roll your own. ... I know that, just needed the exercise.)
1. File::Next
2. File::Fu
3. File::Find::Object
4. File::Finder
5. File::Find

kellert at ohsu.edu<mailto:kellert at ohsu.edu>

On Feb 18, 2010, at 11:40 AM, Eric Wilhelm wrote:

# from Tom Keller
# on Thursday 18 February 2010 11:04:

I need to be able to process files within a directory tree.

This will give you all of the files and directories under $topdir:

 my @paths = File::Fu->dir($topdir)->find(sub{1});

If your matcher sub returns true, the file is returned.  So for only the

 my @files = File::Fu->dir($topdir)->find(sub{$_->is_file});

The filenames returned are File::Fu::File objects relative to wherever
$topdir is relative to (i.e. absolute if $topdir is absolute.)

If you want an iterator instead of one big list, you can use the
finder() method.

 my $iter = File::Fu->dir($topdir)->finder(sub{1});

 while(defined(my $path = $iter->())) {
   $path or next;


There is currently some better documentation for find(), finder(), and
the knob in my svn trunk:


Issues of control, repair, improvement, cost, or just plain
understandability all come down strongly in favor of open source
solutions to complex problems of any sort.
--Robert G. Brown
Pdx-pm-list mailing list
Pdx-pm-list at pm.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/pdx-pm-list/attachments/20100218/6e261f23/attachment-0001.html>

More information about the Pdx-pm-list mailing list