Nested loops with glob or (very very dirty) regex.
First: for (1..12) { for (1..12) { for (1..12) {...}}}
#!/usr/bin/perl
use strict;use warnings;
my $num =3;
$"=',';print join "\n",glob join "_",("{@{ [1..12] }}")x$num;
___END___
1_1_1
1_1_2
1_1_3
1_1_4
1_1_5
1_1_6
...
12_12_7
12_12_8
12_12_9
12_12_10
12_12_11
12_12_12
same thing (without $num param) than:
print join "\n", glob "{1,2,3,4}_{1,2,3,4}_{1_2_3_4}";
Second: for $i (1 .. 12) { for $j ($i+1 .. 12) { for $k ($j+1 .. 12) {...}}}
#!/usr/bin/perl
use strict;no strict 'refs';use warnings;use re 'eval';
my $num =3;
$"='.*?';"@{ [1..12] }" =~ /@{[ ('\b(\d+)\b')x $num]}(?{{print ((j
+oin "_",map {$$_}1..$num),"\n")}})(?!)/;
__END__
1_2_3
1_2_4
1_2_5
1_2_6
1_2_7
...
8_11_12
9_10_11
9_10_12
9_11_12
10_11_12
same thing (without $num param) than:
"1 2 3 4" =~ /\b(\d+)\b.*?\b(\d+)\b(?{{print "$1_$2\n"}})(?!)/;
Update: $" ($LIST_SEPARATOR) permits "implicit join" (for an array interpolated in a string) |