Compare two binary files
8
Is this file the same as that file? The files may or may not be binary. We could compare the modify dates, or the sizes. But, those are not very accurate to know if a file has really changed.
Introducing MD5 Checksum. We can feed the files into Digest::MD5 in binary mode.
This is a great way to do Incremental Backups.
This is also an easy way to verify checksums when downloading files from the internet which list their MD5 Checksums.
You'll need the Digest::MD5 Perl Module.
Introducing MD5 Checksum. We can feed the files into Digest::MD5 in binary mode.
This is a great way to do Incremental Backups.
This is also an easy way to verify checksums when downloading files from the internet which list their MD5 Checksums.
You'll need the Digest::MD5 Perl Module.
use strict;
use Digest::MD5 qw(md5_base64);
if ($#ARGV != 1) {
print "Two files as arguments, please\n";
exit;
}
my $file1 = $ARGV[0];
my $file2 = $ARGV[1];
open (FILE1, $file1);
binmode FILE1;
my $checksum1 = Digest::MD5->new->addfile(*FILE1)->b64digest;
close FILE1;
open (FILE2, $file2);
binmode FILE2;
my $checksum2 = Digest::MD5->new->addfile(*FILE2)->b64digest;
close FILE2;
if ($checksum1 ne $checksum2) {
print "'$file1' is NOT identicle to '$file2'\n";
print "'$file1' = $checksum1\n";
print "'$file2' = $checksum2\n";
}
else {
print "'$file1' is identicle to '$file2'\n";
print "'$file1' = $checksum1\n";
print "'$file2' = $checksum2\n";
}





There are currently no comments for this snippet.