Probably the quickest way I can think of would be to use one of the Digest::* modules, such as Digest::MD5 to compute a digest of the two files, and compare those. Taking from the sample code of the Digest::MD5 module, the following (*untested*) code might do something along the lines of what you wish. (Filenames would be provided on the command line.)

#!/usr/bin/perl -w use strict; use Digest::MD5; if (! scalar(@ARGV)) { print <<USAGE; Usage: $0 file1 file2 ... fileN USAGE exit; } my (%md5sums); foreach my $filename (@ARGV) { open(FILE, $filename) or die("Can't open '$filename': $!"); binmode(FILE); my $digest = Digest::MD5->new->addfile(*FILE)->hexdigest; $md5sums{'by-name'}{$filename} = $digest; push(@{$md5sums{'by-digest'}{$digest}}, $filename); close(FILE); } print "By checksum:\n"; foreach my $digest (sort(keys(%{$md5sums{'by-digest'}}))) { print $digest, ": \n"; foreach my $filename (sort(@{$md5sums{'by-digest'}{$digest}})) { print "\t", $filename, "\n"; } } print "\n"; print "By filename:\n"; foreach my $filename (sort(keys(%{$md5sums{'by-name'}}))) { print $md5sums{'by-name'}{$filename}, ': ', $filename, "\n"; }

In reply to Re: Binary diff in Perl by atcroft
in thread Binary diff in Perl by cool_ravi2

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.