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)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.