in reply to How do I verify that a copied file's contents did not corrupt/modify?

Off the top of my head, if you're not worried about exactly which bytes differ, I would take the MD5 digests of the files and see if these differ. Something like the following will work:
#! /usr/bin/perl -w use strict; use Digest::MD5; my $orig = shift or die "no original given\n"; my $dup = shift or die "no copy given\n"; open ORIG, $orig || die "Cannot open $orig for input: $!\n"; my $origmd5 = Digest::MD5->new; my $origdig = $origmd5->addfile( *ORIG )->digest; close ORIG; open DUP, $dup || die "Cannot open $dup for input: $!\n"; my $dupmd5 = Digest::MD5->new; my $dupdig = $dupmd5->addfile( *DUP )->digest; print( $origdig ne $dupdig ? 'not ' : '', "ok\n" );
  • Comment on Re: How do I verify that a copied file's contents did not corrupt/modify?
  • Download Code

Replies are listed 'Best First'.
Re: Re: How do I verify that a copied file's contents did not corrupt/modify?
by idnopheq (Chaplain) on Mar 14, 2001 at 17:59 UTC
    Tried your code and I am seeing the same thing, even on the localhost's own file system. Interrestingly I tried it on two seperate copies, /opt/hello and /tmp/hello, and those two DO compare via Digest::MD5! Neither's hash matches that of the original. This is true on W2K, GNU/Linux, and Solaris, perl 5.6.0.