Number::Range::Regex::Iterator - create iterators for Number::Range::Regex objects
use Number::Range::Regex; my $it = rangespec( '-5..-3,3..5' )->iterator(); $it->first(); do { do_something_with_value( $it->fetch ); } while ($it->next); $it->last(); do { do_something_with_value( $it->fetch ); } while ($it->prev);
$it = Number:Range::Regex::Iterator->new( $range );
given a range, return an iterator that returns its members. note that this is identical to the more compact, usual form:
$range->iterator()
return the integer currently pointed to by the iterator.
$range->first();
set the iterator to point at its lowest value. first() will throw an error if called on a range with no lower bound, for example:
range( undef, $n )->iterator->first;
$range->last();
set the iterator to point at its greatest value. last() will throw an error if called on a range with no upper bound, for example:
rangespec( '3..inf' )->iterator->first;
point to the next greatest integer that is part of $range. often this value will be one greater, but in the case of compound ranges, it will not always. consider:
my $it = range( '4,22..37' )->iterator; $it->first; # $it->fetch == 4 $it->next; # $it->fetch == 22
$range->prev()
point to the next smallest integer that is part of $range. often this value will be one smaller, but not always:
my $it = range( '22..37,44' )->iterator; $it->last; # $it->fetch == 44 $it->prev; # $it->fetch == 37
$range->iterator->seek( $n );
set the iterator to point to the value $n in $range. that is:
$it->seek( $n )->fetch == $n
if $n is not member of $range, seek() throws an error.
$range->size();
Returns the size of the iterator. If the iterator is unbounded, returns undef.
$range->in_range();
returns a boolean value indicating whether $range has been set to a valid position with any of the methods first, last, seek, prev, and next. returns false in e.g. the following circumstances: $range->last->next; $range->first->prev; range( '3..4' )->first->next->next; range( '3..4' )->last->prev->prev;
Please report any bugs or feature requests through the web interface at http://rt.cpan.org.
Brian Szymanski <ski-cpan@allafrica.com> -- be sure to put Number::Range::Regex in the subject line if you want me to read your message.
Number::Range::Regex
To install Number::Range::Regex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Number::Range::Regex
CPAN shell
perl -MCPAN -e shell install Number::Range::Regex
For more information on module installation, please visit the detailed CPAN module installation guide.