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:

  • 0 if the files are equal β€” slay, same energy πŸ’–
  • 1 if the files are unequal β€” not the same, bestie πŸ™ˆ
  • -1 if 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