Your skill will accomplishwhat the force of many cannot PerlMonks

comment on

 Need Help??

A google search for "perl combinations and permutations" yielded Permutations and combinations. Since you are creating permutations of the given arrays, the name of the subroutine should probably be permute:

```print "[", join(", ", @\$_), "]\n" for permute(
[qw( red green blue )],
[qw( north south east west )],
[1 .. 3],
);

# authored by merlyn
sub permute {
my \$last = pop @_;
unless (@_) {
return map [\$_], @\$last;
}
return map { my \$left = \$_; map [@\$left, \$_], @\$last } permute(@_);
}

__DATA__
[red, north, 1]
[red, north, 2]
[red, north, 3]
[red, south, 1]
[red, south, 2]
[red, south, 3]
[red, east, 1]
[red, east, 2]
[red, east, 3]
[red, west, 1]
[red, west, 2]
[red, west, 3]
[green, north, 1]
[green, north, 2]
[green, north, 3]
[green, south, 1]
[green, south, 2]
[green, south, 3]
[green, east, 1]
[green, east, 2]
[green, east, 3]
[green, west, 1]
[green, west, 2]
[green, west, 3]
[blue, north, 1]
[blue, north, 2]
[blue, north, 3]
[blue, south, 1]
[blue, south, 2]
[blue, south, 3]
[blue, east, 1]
[blue, east, 2]
[blue, east, 3]
[blue, west, 1]
[blue, west, 2]
[blue, west, 3]

As you can see, his method returns a list of permutations, and each permutation is contained inside an array reference. By doing this, he has deferred the decision of formatting the output to the client and he does not have to worry about that portion of the code, which has been distilled to a simple print "[", join(", ", @\$_), "]\n" for permute().

jeffa

```L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
```

In reply to Re: RFC: Playing with glob by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-05-23 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you prefer to work remotely?

Results (82 votes). Check out past polls.

Notices?