is there a module and doc for combination? if so, would you tell me
where i can get them?
i'm trying to get the most possible combination of elements from 3
arrays (not equal in size).
@one = qw(blue green yellow)
@two = qw(john nancy)
@three = qw(north south east west)
no repeat and order matters.
i am open for any (intellectual) suggestion if there is another away
of doing this.
tia,
r-e
another perl newbie
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
: i'm trying to get the most possible combination of elements from 3
: arrays (not equal in size).
:
: @one = qw(blue green yellow)
: @two = qw(john nancy)
: @three = qw(north south east west)
:
: no repeat and order matters.
my @combs;
foreach my $a (@one) {
foreach my $b (@two) {
foreach my $c (@three) {
push @combs, [$a, $b, $c];
}
}
}
If you wanted, you could take the resulting @combs and compute all
possible permutations of those too.
Greg
--
Must one first batter their ears, that they may learn to hear with
their eyes? Must one clatter like kettledrums and penitential
preachers? Or do they only believe the stammerer?
-- Nietzsche
my @out = ("");
foreach ([@three], [@two], [@one]) {
@out = map {my $new = $_; map {length () ? "$new, $_" : $new} @out}
@$_;
}
$" = "\n"; print "@out\n";