[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] Iterators
On Nov 24, 2008, at 3:20 PM, <jay@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@petdance.com => www.petdance.com => AIM:petdance