Comparing digests of the data is one way to do this i.e.
use strict; use warnings; use Digest::SHA; open my $in_1, '/tmp/f1.txt'; open my $in_2, '/tmp/f2.txt'; my $hash1 = Digest::SHA::sha1_hex( do { local $/; <$in_1> } ); my $hash2 = Digest::SHA::sha1_hex( do { local $/; <$in_2> } ); die "The files are NOT the same\n" unless $hash1 eq $hash2; print "The file contents are identical\n";
If your files are really large i.e. in the order of a few gigabytes you could use md5sum on the command line to compare the files instead :
md5sum file1 file2 file3 etc
Identical files will yield identical hashes. This is useful because you do not have to load the entire file into memory first.

In reply to Re: file comparison by bluestar
in thread file comparison by sqspat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.