http://www.perlmonks.org?node_id=1193779


in reply to Minimally changing combinations

What do you need a module for?

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1193761 use strict; use warnings; my @list1 = qw( a b c ); my @list2 = qw( 1 2 ); my $reverse = 0; my @combinations = map { my $left = $_; map "$left $_", $reverse++ % 2 ? reverse @list2 : @list2 } @list1; print for @combinations;

Replies are listed 'Best First'.
Re^2: Minimally changing combinations
by Anonymous Monk on Jun 28, 2017 at 14:20 UTC
    Good point. The OP says "combination", but it appears that what he actually wants is the Cartesian product.