1 ---+ Package =TWiki::LineIterator=
3 Iterator over the lines in a file
10 Create a new iterator over the given file. if the file cannot be opened, then
11 there will be no elements in the iterator.
14 ---++ hasNext() -> $boolean
16 Returns false when the iterator is exhausted.
19 my $it = new TWiki::ListIterator(\@list);
20 while ($it->hasNext()) {
27 Return the next line in the file.
29 The iterator object can be customised to pre- and post-process entries from
30 the list before returning them. This is done by setting two fields in the
33 * ={filter}= can be defined to be a sub that filters each entry. The entry
34 will be ignored (next() will not return it) if the filter returns false.
35 * ={process}= can be defined to be a sub to process each entry before it
36 is returned by next. The value returned from next is the value returned
37 by the process function.
41 my $it = new TWiki::LineIterator("/etc/passwd");
42 $it->{filter} = sub { $_[0] =~ /^.*?:/; return $1; };
43 $it->{process} = sub { return "User $_[0]"; };
44 while ($it->hasNext()) {