1Iterator(3)           User Contributed Perl Documentation          Iterator(3)
2
3
4

NAME

6       Find::File::Iterator - Iterator interface for search files
7

SYNOPSIS

9         use File::Find::Iterator;
10         my $find = File::Find::Iterator->create(dir => ["/home", "/var"],
11                                                 filter => \&isdir);
12         sub isdir { -d }
13
14         while (my $f = $find->next) { print "file : $f\n" }
15
16         #reread with different filter
17         $find->filter(\&ishtml);
18         $find->first;
19         while (my $f = $find->next) { print "file : $f\n" }
20
21         sub ishtml { /\.html?$/ }
22
23         # using file for storing state
24         $find->statefile($statefile);
25         $find->first;
26         # this time it could crash
27         while (my $f = $find->next)
28         { print "file : $f\n" }
29
30         # using imap and igrep
31         use File::Find::Iterator qw(imap igrep);
32         my $find = File::Find::Iterator->new(dir => ["/home", "/var"]);
33         $find = imap { -M } igrep { -d } $find;
34

DESCRIPTION

36       Find::File::Iterator is an iterator object for searching through
37       directory trees. You can easily run filter on each file name. You can
38       easily save the search state when you want to stop the search and
39       continue the same search later.
40
41       Find::File::Iterator inherited from Class::Iterator so you can use the
42       imap and the igrep constructor.
43
44       create(%opt)
45           This is the constructor. The %opt accept the following key :
46
47           dir "=> \@dir"
48               which take a reference to a list of directory.
49
50           filter "=> \&code"
51               which take a code reference
52
53           statefile "=> $file"
54               which take a filename
55
56       next
57           calling this method make one iteration. It return file name or
58           "undef" if there is no more work to do.
59
60       first
61           calling this method make an initialisation of the iterator.  You
62           can use it for do a search again, but with some little change
63           (directory root, statefile option, different filter).
64
65       dir([ \@dir ])
66           this method get or set the directory list for the search.
67
68       filter([ \&code ])
69           this method get or set the filter method use by "next" method.
70
71       statefile([ $file ])
72           this method get or set the name of the file use for store state of
73           the search (see "STORING STATE").
74

STORING STATE

76       If the option "statefile" of the constructor or the "statefile" field
77       of the object is set, the iterator use the Storable module to record is
78       internal state after one iteration and to set is internal state before
79       a new iteration. With this mechanism you can continue your search after
80       an error occurred.
81

SEE ALSO

83       Class::Iterator
84

CREDITS

86       Marc Jason Dominius's YAPC::EU 2003 classes.
87

AUTHOR

89       Robert Silve <robert@silve.net>
90
91
92
93perl v5.36.0                      2023-01-20                       Iterator(3)
Impressum