[oak perl] Comparing two files

James Keenan jkeen at verizon.net
Sun May 29 16:12:51 PDT 2005


> From: "M. Lewis" <cajun at cajuninc.com>
>
> I'm writing a script to compare two text files ($shortfile & 
> $longfile).
> If a line appears in $shortfile, but that line is not in $longfile, 
> then
> I want to write that line out to $differences
>
> I'm relatively certain it is not efficient to open $longfile for each
> entry in $shortfile. Both files are of the magnitude of 800+ lines.

As Michael Paoli and Mark Bole have noted these files are small enough 
that you can slurp them into memory and deal with them as arrays or 
hashes.

My List-Compare module, available on CPAN, has methods such as 
get_unique() and get_difference() which might be useful in this 
respect.  It can handle either arrays or hashes as arguments.

Jim Keenan



More information about the Oakland mailing list