Hi fellow Monks,

I have a task at hand. Being a beginner, I don't have much idea how to approach this problem. Please enlighten me as to how I can do this in Perl.

Given are,

a) Two sets of variables, say First: {A,B,C..} and Second: {X}, where A,B,C and X are all categorical variables, for example, A can take any number of values such as 0,1,2..etc. Same is the case for other variables. For simplicity, consider that all categorical values in each variable starts from 0.

b) Number of variables present in the first set namely, {A,B,C..} may change, ie it can have any number of variables.

c) First set {A,B,C} is ordered within itself, say A corresponds to 0, B corresponds to 1, C corresponds to 2 and X corresponds to 4. The number assigned to X is always more than the numbers assigned to variables in the first set.

Thus for a particular case, we are given First and Second sets with possible values each variable can take.

Task: Design a function that returns a tabular output something like this (assuming two values each in the four variables, although in reality there can be many more variables, each containing any number of values):

A B C X 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1

Please note, the number of rows in the table is the product of all values the variables can take. The table essentially is an ordered listing of all possible combinations of values of the variables in First and Second sets. The order is such that the innermost column is looped fastest (column X in this case) followed by C, B and finally A (A being slowest). Each column count starts with 0 and increases as as we move down the table, until all values of that variable are exhausted (see table). We also see that the ordering of variables defined in c) is maintained in this tabular output. The table, thus, enumerates all possible combinations of values of variables in an ordered way.

Thanks a lot, Raj


In reply to Dynamically assigning number of for loops? by newbio

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



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