我有一个包含多行的制表符分隔的文本文件。我编写了一个脚本,在其中将行分配给一个数组,然后我通过正则表达式在数组中搜索,以找到符合某些条件的行。找到匹配项后,我将其写入 Output1。在遍历所有列出的 if 语句(正则表达式)并且仍然不满足条件后,该行被写入输出 2。
在匹配标准和写入输出 1 时,我 100% 工作,但这是我的问题所在:匹配的行也被写入输出 2,以及不匹配的行。我可能犯了一个愚蠢的错误,但我真的看不到它。如果有人可以看看并帮助我,我会非常感激..
非常感谢!:)
Inputfile sample:
skool school
losieshuis pension
prys prijs
eeu eeuw
lys lijs
water water
outoritêr outoritaire
#!/usr/bin/perl-w
use strict;
use warnings;
use open ':utf8';
use autodie;
open OSWNM, "<SecondWordsNotMatched.txt";
open ONIC, ">Output1NonIdenticalCognates.txt";
open ONC, ">Output2NonCognates.txt";
while (my $line = <OSWNM>)
{
chomp $line;
my @Row = $line;
for (my $x = 0; $x <= $#Row; $x++)
{
my $RowWord = $Row[$x];
#Match: anything, followed by 'y' or 'lê' or 'ê', followed by anything, followed by
a tab, followed by anything, followed by 'ij' or 'leggen' or 'e', followed by anything
if ($RowWord =~ /(.*)(y|lê|ê)(.*)(\t)(.*)(ij|leggen|e)(.*)/)
{
print ONIC "$RowWord\n";
}
#Match: anything, followed by 'eeu', followed by 'e' or 's', optional, followed by
anyhitng, followed by a tab, followed by anything, followed by 'eeuw', followed by 'en', optional
if ($RowWord =~ /(.*)(eeu)(e|s)?(\t)(.*)(eeuw)(en)?/)
{
print ONIC "$RowWord\n";
}
else
{
print ONC "$RowWord\n";
}
}
}