You're using say instead of print, so whitespace certainly is involved.
You disabled the layers on reading the data back but did you disable the layers when writing the file? I think you're usually on Windows and there, Perl (and say) will usually output \r\n to files.
Update:On further inspection, the file sizes of the two files are identical, so there is something else afoot. Sorry for this noise.
I looked at replicating your situation using IO layers, but while I can provoke a difference using the :crlf filehandle, I don't get the digests you posted:
#!perl
use 5.14.0;
use strict;
use warnings;
use Carp;
use Data::Dumper;
use Digest::MD5;
use File::Compare (qw| compare |);
use File::Temp qw( tempfile );
use Test::More tests => 1;
my $basic = 'x' x 10**2;
my @digests;
my ($fh1, $t1) = tempfile();
binmode $fh1, ':raw';
for (1..100) { say $fh1 $basic }
close $fh1 or croak "Unable to close $t1 after writing";
push @digests, hexdigest_one_file($t1);
diag "$t1: $digests[0]";
my $t3 = File::Temp->new( UNLINK => 0);
binmode $t3, ':crlf';
for (1..100) { say $t3 $basic }
close $t3 or croak "Unable to close $t3 after writing";
push @digests, hexdigest_one_file($t3);
diag "$t3: $digests[1]";
is $digests[0], $digests[1];
sub hexdigest_one_file {
my $filename = shift;
say "Filename: $filename";
#open my $FH, '<', $filename or croak "Unable to open $filename fo
+r reading";
#print for <$FH>;
#close $FH;
my $state = Digest::MD5->new();
open my $FH, '<:raw', $filename or croak "Unable to open $filename
+ for reading";
$state->addfile($FH);
close $FH or croak "Unable to close $filename after reading";
return $state->hexdigest;
}
1..1
Filename: /tmp/MdfRQx3DVl
# /tmp/MdfRQx3DVl: e395fd01f84d7d1006a99e2a6b8fb832
Filename: /tmp/x589MI1yYB
# /tmp/x589MI1yYB: 7651c6edc9ebdcfa617bcc99e1c8a6f2
not ok 1
# Failed test at tmp.pl line 29.
# got: 'e395fd01f84d7d1006a99e2a6b8fb832'
# expected: '7651c6edc9ebdcfa617bcc99e1c8a6f2'
# Looks like you failed 1 test of 1.
Update2 Have you asked md5sum about which sum is correct? For my code, md5sum outputs hashes identical to what Perl computes for each file. |