in reply to Re^2: Generating combinatorial strings
in thread Generating combinatorial strings

#! perl -slw use strict; sub nFor(&@) { my $code = shift; die "First argument must be a code ref" unless ref( $code ) eq 'CO +DE'; my @limits = @_; my @indices = ( 0 ) x @limits; for( my $i = $#limits; $i >= 0; ) { $i = $#limits; $code->( @indices ), ++$indices[ $i ] while $indices[ $i ] < $limits[ $i ]; $i = $#limits; $indices[ $i ] = 0, ++$indices[ --$i ] while $i >= 0 and $indices[ $i ] == $limits[ $i ]; } } my @digits = 1 .. 3; ## Set this to the maximum set nFor { my @numbers = @digits[ @_ ]; my $name = join'', @numbers; print $name; } 3, 2, 3; ## Set these to the individual limits. __END__ c:\test>nFor.pl 111 112 113 121 122 123 211 212 213 221 222 223 311 312 313 321 322 323

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"