in reply to compare two files
A basic implementation of this would be:
#!/usr/bin/perl -w use strict; open FILE1, '<', 'file1' || die "Can't open file1: $!"; open FILE2, '<', 'file2' || die "Can't open file2: $!"; my $line1 = <FILE1>; my $line2 = <FILE2>; while ($line1 && $line2) { if ($line1 == $line2) { $line1 = <FILE1>; $line2 = <FILE2>; } else { print $line1; $line1 = <FILE1>; } } print $line1 if defined $line1; while ($line1 = <FILE1>) { print $line1; }
If the files are not sorted (and you're not going to be using them repeatedly), then a hash-based solution such as others have proposed would probably be faster than sorting them and using this method.
|
|---|