我正在将行与两个文本文件ref.txt
(参考)和log.txt
. 但是我想忽略的任何一个文件中都可能有任意数量的空行;我怎样才能做到这一点?
参考文件
one
two
three
end
日志.txt
one
two
three
end
输出中不会有不正确的日志行,换句话说log.txt
,与ref.txt
.
我喜欢用伪代码完成的事情:
while (traversing both files at same time) {
if ($l is blank line || $r is blank line) {
if ($l is blank line)
skip to next non-blank line
if ($r is blank line)
skip to next non-blank line
}
#continue with line by line comparison...
}
我当前的代码:
use strict;
use warnings;
my $logPath = ${ARGV [0]};
my $refLogPath = ${ARGV [1]} my $r; #ref log line
my $l; #log line
open INLOG, $logPath or die $!;
open INREF, $refLogPath or die $!;
while (defined($l = <INLOG>) and defined($r = <INREF>)) {
#code for skipping blank lines?
if ($l ne $r) {
print $l, "\n"; #Output incorrect line in log file
$boolRef = 0; #false==0
}
}