いくつかの行を持つタブ区切りのテキストファイルがあります。行を配列に割り当てるスクリプトを作成し、正規表現を使用して配列を検索し、特定の条件に一致する行を見つけました。一致するものが見つかったら、それをOutput1に書き込みます。リストされているすべてのifステートメント(正規表現)を調べても基準が満たされない場合、その行は出力2に書き込まれます。
一致基準と出力1への書き込みに関しては、100%動作しますが、ここで問題が発生します。一致した行は、一致しない行とともにOutput2にも書き込まれます。私はおそらくばかげた間違いを犯していますが、私は本当にそれを見ることができません。誰かが見てくれて助けてくれたら、本当にありがたいです。
本当にありがとう!:)
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";
}
}
}