In Perl, how can I iterate over the Cartesian product of multiple sets?
Posted
by nubie2
on Stack Overflow
See other posts from Stack Overflow
or by nubie2
Published on 2010-03-16T18:34:58Z
Indexed on
2010/03/16
20:41 UTC
Read the original article
Hit count: 170
perl
|cartesian-product
I want to do permutation in Perl. For example I have three arrays: ["big", "tiny", "small"]
and then I have ["red", "yellow", "green"]
and also ["apple", "pear", "banana"]
.
How do I get:
["big", "red", "apple"] ["big", "red", "pear"] ..etc.. ["small", "green", "banana"]
I understand this is called permutation. But I am not sure how to do it. Also I don't know how many arrays I can have. There may be three or four, so I don't want to do nested loop.
© Stack Overflow or respective owner