Algorithm-GenerateSequence
view release on metacpan or search on metacpan
lib/Algorithm/GenerateSequence.pm view on Meta::CPAN
if ($started++) {
my $max = $#counters;
# mmm, long addition
do {
my $new = ++$counters[ $max ];
# check for overflow
goto DONE if $new % @{ $values[ $max ] };
$counters[ $max ] = 0;
} while --$max >= 0;
DONE:
if ($max < 0) {
$ended = 1;
return;
}
}
my $i = 0;
return map { $values[ $i++ ][ $_ ] } @counters;
}, ref $class || $class;
}
=head1 next
returns a list containing the next value in the sequence, or false if
at the end of the sequence
=cut
sub next { $_[0]->() }
=head2 as_list
return the remainder of the sequence as a list of array references
=cut
sub as_list {
my $self = shift;
my @results;
while (my @next = $self->()) {
push @results, \@next;
}
return @results;
}
1;
__END__
=head1 BUGS
None currently known. If you find any please make use of
L<http://rt.cpan.org> by mailing your report to
bug-Algorithm-GenerateSequence@rt.cpan.org, or contact me directly.
=head1 AUTHOR
Richard Clamp <richardc@unixbeard.net>
=head1 COPYRIGHT
Copyright (C) 2003 Richard Clamp. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
( run in 1.413 second using v1.01-cache-2.11-cpan-df04353d9ac )