use 5.006;
use strict;
use warnings;
require Exporter;
use Carp;
$VERSION = '1.1003';
@EXPORT_OK = qw(cmp compare_text);
sub compare {
croak("Usage: compare( file1, file2 [, buffersize]) ")
unless(@_ == 2 || @_ == 3);
croak("from undefined") unless (defined $from);
croak("to undefined") unless (defined $to);
if (ref($from) &&
} elsif (ref(\$from) eq 'GLOB') {
} else {
unless ($text_mode) {
binmode FROM;
}
$closefrom = 1;
}
if (ref($to) &&
} elsif (ref(\$to) eq 'GLOB') {
} else {
$closeto = 1;
}
# If both are opened files we know they differ if their size differ
}
if ($text_mode) {
local $/ = "\n";
if (ref $size) {
# $size contains ref to comparison function
} else {
}
}
}
else {
}
goto fail_inner;
}
}
}
return 0;
# All of these contortions try to preserve error messages...
return 1;
if ($closefrom) {
my $status = $!;
$! = 0;
close FROM;
$! = $status unless $!;
}
return -1;
}
sub cmp;
*cmp = \&compare;
sub compare_text {
croak("Usage: compare_text( file1, file2 [, cmp-function])")
unless @_ == 2 || @_ == 3;
croak("Third arg to compare_text() function must be a code reference")
# Using a negative buffer size puts compare into text_mode too
}
1;
=head1 NAME
File::Compare - Compare files or filehandles
=head1 SYNOPSIS
use File::Compare;
if (compare("file1","file2") == 0) {
print "They're equal\n";
}
=head1 DESCRIPTION
The File::Compare::compare function compares the contents of two
sources, each of which can be a file or a file handle. It is exported
from File::Compare by default.
File::Compare::cmp is a synonym for File::Compare::compare. It is
exported from File::Compare only by request.
File::Compare::compare_text does a line by line comparison of the two
files. It stops as soon as a difference is detected. compare_text()
accepts an optional third argument: This must be a CODE reference to
a line comparison function, which returns 0 when both lines are considered
equal. For example:
compare_text($file1, $file2)
is basically equivalent to
compare_text($file1, $file2, sub {$_[0] ne $_[1]} )
=head1 RETURN
File::Compare::compare and its sibling functions return 0 if the files
are equal, 1 if the files are unequal, or -1 if an error was encountered.
=head1 AUTHOR
File::Compare was written by Nick Ing-Simmons.
Its original documentation was written by Chip Salzenberg.
=cut