Your code is invoking O(n squared) behavior. You should use a hash as a set type, instead of linearly comparing each line to the entire other file contents.
As a brief example, the core of your program can be:
my %compare;
my %files = ( a => 'oldfile', b => 'newfile' ); # compare oldfile to n
+ewfile
for my $filekey (keys %files) {
open F, $files{$filekey} or next;
while (<F>) {
next if /^(#.*)\s*$/; # ignore blanks and comments
$compare{lc $_} .= $filekey;
}
}
print "Lines in newfile but not oldfile:\n",
sort grep $compare{$_} !~ /a/, keys %compare;
print "Lines in oldfile but not newfile:\n",
sort grep $compare{$_} !~ /b/, keys %compare;
I used this technique in
a recent post as well, and you might
see it clearer there.
-- Randal L. Schwartz, Perl hacker