in reply to Dynamically assigning number of for loops?

I think all you need is a binary counter, like this:
$vars = 4; # number of bits for my $i (0 .. (1<<$vars)-1) { printf "%0${vars}b\n", $i; }
Well, you might want to spread the cell entries a little, so you'll have fun figuring that out. :)

As for the header: you can cheat. All you have to do is sort the names in order of value, and print them out first. Above the table the code here creates.

And $vars in the above code must be the same as your number of variables. More beginners' fun.