Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: In need of a sequence iterator.

by !1 (Hermit)
on Dec 02, 2004 at 16:30 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found