[Omaha.pm] Iterators
Andy Lester
andy at petdance.com
Mon Nov 24 14:06:34 PST 2008
On Nov 24, 2008, at 3:20 PM, <jay at jays.net> wrote:
> Survey: Am I the only one who's coded Perl for 15 years now and
> never knew
> about iterators?
>
> http://www.perl.com/pub/a/2005/06/16/iterators.html
File::Next makes great use of iterators, if I do say so myself.
use File::Next;
my $iter = File::Next::files( '/tmp' );
while ( defined ( my $file = $iter−>() ) ) {
print $file, "\n";
}
You don't care what goes on behind the scenes. Also means you can
have multiple iterators:
my $iter_tmp = File::Next::files( '/tmp' );
my $iter_usr = File::Next::files( '/usr' );
and they can work by themselves without disturbing the other one.
xoxo,
Andy
--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance
More information about the Omaha-pm
mailing list