Array::IteratorArray::Iterator is a simple class for iterating over Perl arrays. | |
Download |
Array::Iterator Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Stevan Little
- Publisher web site:
- http://search.cpan.org/~stevan/
Array::Iterator Tags
Array::Iterator Description
Array::Iterator is a simple class for iterating over Perl arrays. Array::Iterator is a simple class for iterating over Perl arrays.SYNOPSIS use Array::Iterator; # create an iterator with an array my $i = Array::Iterator->new(1 .. 100); # create an iterator with an array reference my $i = Array::Iterator->new(@array); # create an iterator with a hash reference my $i = Array::Iterator->new({ __array__ => @array }); # a base iterator example while ($i->hasNext()) { if ($i->peek() < 50) { # ... do something because # the next element is over 50 } my $current = $i->next(); # ... do something with current } # shortcut style my @accumulation; push @accumulation => { item => $iterator->next() } while $iterator->hasNext(); # C++ ish style iterator for (my $i = Array::Iterator->new(@array); $i->hasNext(); $i->next()) { my $current = $i->current(); # .. do something with current } # common perl iterator idiom my $current; while ($current = $i->getNext()) { # ... do something with $current }This class provides a very simple iterator interface. It is is uni-directional and can only be used once. It provides no means of reverseing or reseting the iterator. It is not recommended to alter the array during iteration, however no attempt is made to enforce this (although I will if I can find an efficient means of doing so). This class only intends to provide a clear and simple means of generic iteration, nothing more (yet).Requirements:· Perl Requirements: · Perl
Array::Iterator Related Software