I want to do permutation in Perl. For example I have three arrays: [\"big\", \"tiny\", \"small\"]
and then I have [\"red\", \"yellow\", \"green\"]
IF
then you can simply do this:
For two arrays @xs
and @ys
:
map{ my $x = $_; map { [$x, $_] } @ys } @xs
For three arrays @xs
, @ys
, @zs
map{ my $x = $_; map { my $y = $_; map { [$x, $y, $_] } @zs } @ys } @xs