in reply to Re: In need of a sequence iterator.
in thread In need of a sequence iterator.
As far as I can see this is just counting in base $count, in which case I'd probably use a string instead:
sub genIterator { my($len, $count) = @_; my $cur = ''; my $lastdig = $count - 1; return sub { if (length($cur) < $len) { $cur .= '0'; } else { $cur =~ s/([^$lastdig])$lastdig*\z/$1 + 1/e or $cur = undef; } $cur; } }
Of course this assumes $count doesn't exceed 10; this approach gets a bit more complex if you need to deal with larger bases.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: In need of a sequence iterator.
by BrowserUk (Patriarch) on Dec 02, 2004 at 17:50 UTC | |
by hv (Prior) on Dec 03, 2004 at 12:53 UTC |