Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Generate sequential array element combos (.. and ++)

by tye (Sage)
on Jul 28, 2004 at 05:37 UTC ( [id://377929]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Generate sequential array element combos
in thread Generate sequential array element combos

For that case you can get as simple as

for( map '0'x$_ .. '9'x$_, 4..6 ) {

but that chews up quite a chunk of memory. You can use tons less memory with something like

for my $len ( 4 .. 6 ) { my $pat = '0' x $len; while( $len == length $pat ) { # ... $pat++; } }

But, of course, that won't help much if you hope to change your list of characters to something other than 0..9.

Algorithm::Loops would probably be quite helpful for this if you do hope to use characters other than digits. But I think I'll not code an example for that at this point, though it can be done fairly simply (or more complexly if you want a single iterator, for example).

- tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found