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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.