Find::File::Iterator - Iterator interface for search files
use File::Find::Iterator; my $find = File::Find::Iterator->new(dir => ["/home", "/var"], filter => \&isdir); sub isdir { -d }
while (my $f = $find->next) { print "file : $f\n" } #reread with different filter $find->filter(\&ishtml); $find->first; while (my $f = $find->next) { print "file : $f\n" }
sub ishtml { /\.html?$/ }
# using file for storing state $find->statefile($statefile); $find->first; # this time it could crash while (my $f = $find->next) { print "file : $f\n" }
# using imap and igrep use File::Find::Iterator qw(imap igrep); my $find = File::Find::Iterator->new(dir => ["/home", "/var"]); $find = imap { -M } igrep { -d } $find;
Find::File::Iterator is an iterator object for searching through directory trees. You can easily run filter on each file name. You can easily save the search state when you want to stop the search and continue the same search later.
Find::File::Iterator inherited from the Class::Iterator manpage so you can use the imap and the igrep constructor.
create(%opt)
This is the constructor. The %opt accept the following key :
=> \@dir
which take a reference to a list of directory.
=> \&code
which take a code reference
=> $file
which take a filename
calling this method make one iteration. It return file name or
undef if there is no more work to do.
calling this method make an initialisation of the iterator. You can use it for do a search again, but with some little change (directory root, statefile option, different filter).
this method get or set the directory list for the search.
this method get or set the filter method use by next method.
this method get or set the name of the file use for store state of the search (see STORING STATE).
If the option statefile of the constructor or the statefile field
of the object is set, the iterator use the the Storable manpage module to record
is internal state after one iteration and to set is internal state before
a new iteration. With this mechanism you can continue your search after
an error occurred.
Marc Jason Dominius's YAPC::EU 2003 classes.
Robert Silve <robert@silve.net>