File::Compare(3pm)
π NAME π
File::Compare β compare files or filehandles, bestie. This is the File::Compare(3pm) page from the Perl Programmers Reference Guide, and it's here to settle the "are these two things the same?" question without drama. β¨
β¨ SYNOPSIS β¨
use File::Compare;
if (compare("file1", "file2") == 0) {
print "They're equal\n";
}
π DESCRIPTION π
Okay so the main compare function (File::Compare::compare) compares the contents of two sources, and each source can be a file or a file handle π«Ά. It is exported from File::Compare by default β no extra asking required.
Also, File::Compare::cmp is a synonym for File::Compare::compare. It is exported from File::Compare only by request, so speak up if you want it. π
File::Compare::compare_text does a line by line comparison of the two files. It stops as soon as a difference is detected β like it literally clocks the first mismatch and dips π. 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]} )
π RETURN π
File::Compare::compare and its sibling functions return:
0if the files are equal β slay, same energy π1if the files are unequal β not the same, bestie π-1if an error was encountered β oop, something went wrong π
π AUTHOR π
File::Compare was written by Nick Ing-Simmons. Its original documentation was written by Chip Salzenberg. π
That's the whole vibe β this page is from perl v5.42.3, dated 2026-11-03, and it's the File::Compare(3pm) manual page. Bye bestie! π¦
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms