in reply to loop in loop method evasion

You actual intent is a little unclear to me. Are you generating permutations with n terms of the list of items in @chartab followed by a comma? If so, recursion would seem the reasonable way to go. Something like (untested):

use strict; use warnings; my @chartab = (0..9, 'a'..'z'); my $depth = 4; print permute(\@chartab,'',$depth); sub permute { my ($chartab_ref, $intro, $depth) = @_; return "$intro," if ($depth == 0); my $string = q{}; foreach my $letter (@$chartab_ref) { $string .= permute($chartab_ref, $intro.$letter,$depth-1); } return $string; }

Replies are listed 'Best First'.
Re^2: loop in loop method evasion
by ikegami (Patriarch) on Dec 26, 2009 at 06:34 UTC

    While your algorithm does what the OP wants, it is misnamed. It does not return the permutations of the list. The list only contains one zero, yet the output contains strings with multiple zeroes.