#!/usr/bin/perl -w use strict; my @chars = ('a' .. 'z', 'A' .. 'Z', 0 .. 9); my $length = 8; my $get_combo = nestedLoops([ ([@chars]) x $length ]); my @list; while( @list= $get_combo->() ) { print "@list\n"; } # tye's nestedLoops code for future Algorithm::Loops sub nestedLoops { my( $loops, $params )= @_; my $code= $params && $params->{Code}; my @list; my $when= $params && $params->{OnlyWhen} || sub { @_ == @$loops }; my $i= -1; my @idx; my @vals= @$loops; my $iter= sub { while( 1 ) { # Prepare to append one more value: if( $i < $#$loops ) { $idx[++$i]= -1; $vals[$i]= $loops->[$i]->(@list) if 'CODE' eq ref $loops->[$i]; } # Increment furthest value, chopping if done there: while( @{$vals[$i]} <= ++$idx[$i] ) { # Return if all done: return if --$i < 0; pop @list; } $list[$i]= $vals[$i][$idx[$i]]; if( ! ref $when || $when->( @list ) ) { return @list; } } }; return $iter if ! $code; while( $iter->() ) { $code->( @list ); } }