我有一個大約有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