我有一个包含大约 25000 条记录的文件,每条记录有超过 13 个条目是药物名称。我想为这些条目形成所有可能的配对组合。例如:如果一行有三个记录 A、B、C。我应该形成组合为 1) AB 2) AC 3)B C。下面是我从互联网上获得的代码,它仅适用于将单行分配给大批:
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";
}
你能建议我解决这个问题吗?