package TestCompare;
#use strict;
#use diagnostics;
use Carp;
use Exporter;
use FileHandle;
$MYPKG = eval { (caller)[0] };
##--------------------------------------------------------------------------
=head1 NAME
testcmp -- compare two files line-by-line
=head1 SYNOPSIS
$is_diff = testcmp($file1, $file2);
or
$is_diff = testcmp({-cmplines => \&mycmp}, $file1, $file2);
=head2 DESCRIPTION
Compare two text files line-by-line and return 0 if they are the
same, 1 if they differ. Each of $file1 and $file2 may be a filenames,
or a filehandles (in which case it must already be open for reading).
If the first argument is a hashref, then the B<-cmplines> key in the
hash may have a subroutine reference as its corresponding value.
The referenced user-defined subroutine should be a line-comparator
function that takes two pre-chomped text-lines as its arguments
(the first is from $file1 and the second is from $file2). It should
return 0 if it considers the two lines equivalent, and non-zero
otherwise.
=cut
##--------------------------------------------------------------------------
sub testcmp( $ $ ; $) {
unless (ref $fh1) {
}
unless (ref $fh2) {
}
++$line;
last if $diffs;
}
## these two lines must be different
warn "$file1 and $file2 differ at line $line\n";
}
## file1 must be shorter
warn "$file1 is shorter than $file2\n";
}
elsif (defined $f2text) {
## file2 must be longer
warn "$file1 is shorter than $file2\n";
}
return $diffs;
}
1;