我一直在尝试比较两个文件之间的行和匹配相同的行.
由于某种原因,下面的代码只会经过'text1.txt'的第一行并打印'if'语句,无论这两个变量是否匹配.
谢谢
use strict;
open( <FILE1>, "<text1.txt" );
open( <FILE2>, "<text2.txt" );
foreach my $first_file (<FILE1>) {
foreach my $second_file (<FILE2>) {
if ( $second_file == $first_file ) {
print "Got a match - $second_file + $first_file";
}
}
}
close(FILE1);
close(FILE2);
Run Code Online (Sandbox Code Playgroud)