在 Perl 中对数组使用编辑距离

El *_*vid 3 arrays perl edit-distance bioinformatics levenshtein-distance

我正在尝试比较两个数组之间的编辑距离。我尝试过使用 Text:Levenshtein。

#!/usr/bin/perl -w
use strict;
use Text::Levenshtein qw(distance);

my @words = qw(four foo bar);
my @list = qw(foo fear);
my @distances = distance(@list, @words);

print "@distances\n";
#results: 3 2 0 3
Run Code Online (Sandbox Code Playgroud)

然而,我希望结果如下所示:

2 0 3
2 3 2
Run Code Online (Sandbox Code Playgroud)

通过 @words 数组获取 @list 的第一个元素,并对 @list 的其余元素执行相同的操作。我计划将其升级为更大的阵列。

Ora*_*bîg 5

我不确定你到底是什么意思,但我认为这就是你所期望的:

#!/usr/bin/perl -w
use strict;
use Text::Levenshtein qw(distance);

my @words = qw(four foo bar);
my @list = qw(foo fear);

foreach my $word (@list) {
   my @distances = distance($word, @words);
   print "@distances\n";
}
Run Code Online (Sandbox Code Playgroud)