Tengo una matriz (@strings) incluyendo algunas palabras. Quiero generar todas las combinaciones posibles y guardar los resultados en una estructura de datos como una matriz de matriz. Encontré un post "En Perl, ¿cómo puedo generar todas las combinaciones posibles de una lista?"pero no pude guardarlo en una matriz de matriz
#!/usr/bin/perl
use strict;
use warnings;
use Algorithm::Combinatorics qw(combinations);
print join("t", @strings),"n";
AAA BBB CCC DDD EEE
my $iter = combinations(@strings, 2);
while (my $c = $iter->next) {
print "@$cn";
}
Lo intenté:
my @a;
while (my $c = $iter->next) {
push @a, @$c;
}
Respuestas
2 para la respuesta № 1use Algorithm::Combinatorics qw( combinations );
use Parallel::ForkManager qw( );
use constant MAX_WORKERS => 10;
my @strings = ...;
my $pm = Parallel::ForkManager->new(MAX_WORKERS);
my $iter = combinations(@strings, 2);
while (my $c = $iter->next) {
my $pid = $pm->start and next;
exec("program", @$c)
or die("Can"t execute child: $!n");
}