My apologies in advance for posting such an involved question right off the bat.
What I have: a hash of N arrays. Each array belongs to a parameter for a function, and contains the values that the parameter will take on. There are a small, finite number of possible paramters (say 20) and only a handful are used in the hash, but which specific parameters are used may vary from one time I run this to the next. I need to explore the entire parameter space at all the points given.
So, a given instance of the hash is something like this:
my %params = (
x_pos => [1..10],
y_pos => [-5..5],
z_pos => [0..15],
spin => [0, 1],
neato => [1..10]);
And which parameters are included as well as what the ranges are will be decided prior to running.
Generally, I've been using a bunch of nested loops to get all the combinations of parameters:
foreach my $x_pos (@{$params{x_pos}}) {
foreach my $y_pos (@{$params{y_pos}}) {
.
.
.
my $result = function($x_pos,$y_pos,...)
.
.
.
}
}
All these loops are written by hand.
My Question: Is there a way to generalize these loops so that all combinations are used without knowing in advance which parameters or how many are in the hash?
It should be noted that the parameters need to go in a specific order, e.g. that "spin" must be
inside the "*_pos" loops.
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.