【发布时间】:2018-04-17 15:03:15
【问题描述】:
我确定我错过了一些简单的东西。下面的代码我试图用正则表达式不区分大小写(//i)匹配文件的两行。如果文件行在不同情况下不同,它仍然匹配。
在没有模式匹配、遍历文件和逐行比较的情况下,它可以正常工作。只是试图添加不区分大小写。
#add file lines to array for comparison
while (my $fileLine = <FILE1>)
{
chomp($fileLine);
push @lines, $fileLine;
$compare{$fileLine}++;
}
#comparison of second file to first file
while (my $fileLine2 = <FILE2>)
{
chomp($fileLine2);
$lineNum = 1 + $count;
my $comp = $fileLine2;
if ($comp =~ s/$lines[$count]//i)
{
print "The different line is at Line Number: $lineNum \n" unless(exists($compare{$fileLine2}));
print "File A: $fileLine2\n" unless (exists($compare{$fileLine2}));
print "File B: $lines[$count]\n" unless (exists($compare{$fileLine2}));
}
}
【问题讨论】:
-
请不要编辑您的代码以删除您询问的错误。