Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: In need of a sequence iterator.

by !1 (Hermit)
on Dec 02, 2004 at 16:30 UTC ( #411844=note: print w/replies, xml ) Need Help??


in reply to Re^2: In need of a sequence iterator.
in thread In need of a sequence iterator.

Now that I've had a chance to sleep, here's a solution that accepts either a count or an arrayref.

sub genIterator { my ($len,$array) = @_; $array = [0..$array-1] if $array =~ /^\d+$/; die "Don't know what to do with $array" unless ref $array eq "ARRA +Y"; my @list = (); return sub { return undef unless @$array; if (@list < $len) { push @list, 0; } else { $list[-1]++; while (@list && $list[-1] >= @$array) { pop @list; $list[-1]++ if @list; } } return @list ? join("", @$array[@list]) : undef; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://411844]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2021-08-05 09:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?