我有一个大约有25000条记录的文件,每个记录有超过13个条目是药物名称。我想为这些条目形成所有可能的配对组合。例如:如果一条线有三条记录A,B,C,我应该组合成1)AB 2)AC 3)B C.下面是我从互联网上得到的代码,它只在一条线分配给数组:Perl形成字符串随机字符串组合
use Math::Combinatorics;
my @n = qw(a b c);
my $combinat = Math::Combinatorics->new(
count => 2,
data => [@n],
);
while (my @combo = $combinat->next_combination) {
print join(' ', @combo) . "\n";
}
我使用的代码,它不会产生任何输出:
open IN, "drugs.txt" or die "Cannot open the drug file";
open OUT, ">Combination.txt";
use Math::Combinatorics;
while (<IN>) {
chomp $_;
@Drugs = split /\t/, $_;
@n = $Drugs[1];
my $combinat = Math::Combinatorics->new(
count => 2,
data => [@n],
);
while (my @combo = $combinat->next_combination) {
print join(' ', @combo) . "\n";
}
print "\n";
}
能否请你建议我解决这个问题呢?
你的代码的标准是可怕的,我已经通过'perltidy'运行它,从而大大改善了它。对编程不熟悉并不适合马虎和不一致的布局。 – Borodin