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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |