in reply to file comparison using file open in binary mode.

Perhaps avoid reinventing the wheel and just use MD5 or SHA1 sums? See Digest or relatives.

  • Comment on Re: file comparison using file open in binary mode.

Replies are listed 'Best First'.
Re^2: file comparison using file open in binary mode.
by Karger78 (Beadle) on Nov 27, 2009 at 18:11 UTC
    I have tried MD5 etc, the problem is that it appears to include the name in the MD5, so if both files are equal but the name are different the MD5 hash appears to be different.

      That is not the case. Only the content matters.

      gmargo@tesla 1368$ ls -l perl10.pl -rw-r--r-- 1 gmargo gmargo 1150 Oct 16 21:43 perl10.pl gmargo@tesla 1369$ cp perl10.pl perl10a.pl gmargo@tesla 1370$ md5sum -b perl10.pl perl10a.pl 976ed3393d1e967b2d8b4432c92b1397 *perl10.pl 976ed3393d1e967b2d8b4432c92b1397 *perl10a.pl gmargo@tesla 1371$ sha1sum -b perl10.pl perl10a.pl 1f62d2bcc8dcdf3f9ef0f3728f9f99c85eb21d81 *perl10.pl 1f62d2bcc8dcdf3f9ef0f3728f9f99c85eb21d81 *perl10a.pl
        Thanks look's like the MD5 works nicely. one last question, how do i do the comparioson with each value in the hash? This is what i go thus far, but doesn't seem to work.
        while ( my ($key, $value) = each(%hash1) ) { while ( my ($key1, $value1) = each(%hash2) ) { if ($value eq $value1) { print "\n$key => $value\n is equal with\n"; print "$key1 => $value1\n" } } print "$key => $value\n"; }
        ok, let me give md5 a shot again. perhaps i did somthing wrong.