File::Compare(3perl)
π File::Compare π
okay bestie, listen up β this is the page for File::Compare, straight out of the Perl Programmers Reference Guide, section 3perl. It's giving "I just need to know if these two things are the same" and honestly? Same. Let's go π¦
β¨ SYNOPSIS β¨
use File::Compare;
if (compare("file1", "file2") == 0) {
print "They're equal\n";
}
like. that's it. that's the whole vibe. π
πΈ DESCRIPTION πΈ
So the main character here is the function File::Compare::compare. What does it do? It compares the contents of two sources, and each of those sources can be either a file or a file handle. No cap. And here's the cute part β it's exported from File::Compare by default, so the second you use it, it's just there for you. π«Ά
Next up: File::Compare::cmp is literally just a synonym for File::Compare::compare. Exact same thing, different name, iconic behaviour honestly. BUT β and this is the important bit, don't skip it β it is exported from File::Compare only by request. So you gotta ask for it, it's not showing up uninvited. π
And then there's File::Compare::compare_text, which does a line by line comparison of the two files. She's efficient, she's focused β she stops as soon as a difference is detected. No reading the rest of the file for no reason, we love a girl who knows when to walk away. π
compare_text() also accepts an optional third argument, and bestie, this one has rules: it must be a CODE reference to a line comparison function. That function has to return 0 when both lines are considered equal. That's the contract. π
For example:
compare_text($file1, $file2)
is basically equivalent to
compare_text($file1, $file2, sub {$_[0] ne $_[1]} )
see how if you don't pass your own little comparison sub, it just goes ahead and says "not equal if they're not string-equal"? lowkey elegant. β¨
π₯ RETURN π₯
Okay so what do you actually get back from File::Compare::compare and its sibling functions? A number, and it's telling you everything:
0β the files are equal π1β the files are unequal π-1β an error was encountered π
three moods, three numbers. remember them. iykyk. π
π AUTHOR π
File::Compare was written by Nick Ing-Simmons. Its original documentation was written by Chip Salzenberg. kings, both of them. we stan. π«Άπ
and that's the whole page, bestie! this was pulled from perl v5.44.0, dated 2026-10-17, and it's the File::Compare(3perl) manual page. go forth and compare files with confidence β¨ππ¦
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms