我有一个包含一些单词的数组(@string)。我想生成所有可能的组合,并将结果保存在一个类似array of array的数据结构中。我找到一个帖子"In Perl, how can I generate all possible combinations of a list?“,但我不能将它保存在数组的数组中
#!/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 "@$c\n";
}我试过了:
my @a;
while (my $c = $iter->next) {
push @a, @$c;
}发布于 2015-03-12 06:07:04
use 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");
}https://stackoverflow.com/questions/28996978
复制相似问题