whileループに一致する値がいくつか見つからないのはなぜですか? この結果出力は、ファイルを読み取った後にすべての可能な値を戻していません。いくつか欠けている値があります。Perlループで正しい結果がフィルタリングされない
# str_1,2,3,4 are my search strings
while ($line = <$fh>) {
if ($line !~ /$str_1/ && $line =~ /$str_2/) {
open($fh, '>>report.txt');
print $fh "$file : $line";
close $fh;
}
if ($line !~ /$str_3/ && $line =~ /$str_4/) {
open($fh, '>>report.txt');
print $fh "$file : $line";
close $fh;
}
}
出力:例えば
Number of Attendance = 1 INFO:21
Number of Attendance = 2 INFO:21
Number of Attendance = 1 INFO:21
# There are results such as Number of Attendance = 8 INFO:21 which my code is not able to search.
:
#my log file which is the input
Number of Attendance = 1 from XYZ FACI INFO:21
Number of Attendance = 0 from UZQ BLAH INFO:21
Number of Attendance = 8 from WZW BLAH INFO:21
Number of Attendance = 0 from WZW BLAH INFO:21
Number of Attendance = 0 from WZW BLAH INFO:21
Number of Attendance = 0 from WZW BLAH INFO:21
so here my str1 = /Number of Attendance = 0/
str2 = /INFO:21/
#So output for my code now is only
Number of Attendance = 1 from XYZ FACI INFO:21
#But,Expected output should be
Number of Attendance = 1 from XYZ FACI INFO:21
Number of Attendance = 8 from WZW BLAH INFO:21
は、私はそのだけ一度だけ私のすべてのファイルを読み込み、すべての可能な値を返すのではなく、第1の出力値を返すと思います。
あなたは明示的に入力、expeを言いたいことができますか? cted出力とこのコードが出力している出力? – SilentMonk
'$ str1'のパターンが一致したり、' $ str_2'のパターンが一致しないため、 '$ str3'のパターンが一致するか、' $ str_4'のパターンが一致しないためです。 – ikegami