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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |