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.


In reply to Re^3: File::Temp: 2 interfaces get different results with Digest::MD5 and File::Compare by Corion
in thread File::Temp: 2 interfaces get different results with Digest::MD5 and File::Compare by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.