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