This will print out all the combinations recursively from a hash, just not in any usual order. Perl will stringify the numbers if you print them and as each attempt starts with a zero as string, the unneccessary leading zero is trimmed just before printing.

#!/usr/bin/perl use strict; use warnings; my $bikelock; my $zodials = 4; my $constellations = 10; $bikelock = combicracker( {}, $zodials ); print_psychle($bikelock); sub combicracker { my $ref = shift; my $zodials = shift; $ref->{ $_ } = { } for 0 .. $constellations-1; if( --$zodials ){ for my $key ( keys %$ref ){ combicracker( $ref->{ $key }, $zodials ); } } $ref; } sub print_psychle{ my $bref = shift; my $sn = shift || '0'; unless( (keys %$bref)[0] ){ $sn =~ s/\A0//; print "attempt: $sn\n" ; return; } foreach my $attempt_builder ( keys %$bref ){ my $att_b2 = $sn . $attempt_builder; print_psychle( $bref->{$attempt_builder} , $att_b2 ); } }
attempt: 6666 attempt: 6663 attempt: 6667 attempt: 6669 attempt: 6662 attempt: 6668 attempt: 6661 attempt: 6664 attempt: 6660 attempt: 6665 attempt: 6636 attempt: 6633 attempt: 6637 attempt: 6639 attempt: 6632 attempt: 6638 attempt: 6631 attempt: 6634 ... attempt: 0073 attempt: 0077 attempt: 0079 attempt: 0072 attempt: 0078 attempt: 0071 attempt: 0074 attempt: 0070 attempt: 0075 attempt: 0096 ... attempt: 5556 attempt: 5553 attempt: 5557 attempt: 5559 attempt: 5552 attempt: 5558 attempt: 5551 attempt: 5554 attempt: 5550 attempt: 5555

This is an older version of the hash, so it returns somewhat predictably, run for run returns the same order. I think the keys nowadays are gauranteed to be at least seemingly random. Though, there is also a grouped ordering from essentially running through the keys sequentially.


In reply to Re: looping efficiency by Don Coyote
in thread looping efficiency by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.