Lo, The code below gives different results if the binmode statement is removed. All the code does is print the md5sum of a file using Digest::MD5. When I remove the CR from the output file, the md5 agrees with the md5 of the filehandle in the script. So, it looks like the md5 using the filehandle is somehow getting the file without the crlf layer. So, any ideas? I have a workaround, but it has piqued my curiousity... The general logic is 1) Open file, autoflush 2) binmode crlf 3) write "Hello world\n" 4) seek 0,0. 5) Get md5 using filehandle 6) get md5 by opening file
#! /usr/bin/perl -w use strict; use diagnostics; use File::Temp(); use File::Copy; my $FH = File::Temp->new ( TEMPLATE => 'tmpXXXXXXXXXX', SUFFIX => '.xml_out', DIR => '/tmp', UNLINK => 1 ); $FH->autoflush(1); binmode( $FH, ':crlf' ); print $FH "Hello World\n"; my $tgt_file = '/tmp/JD'; copy ( $FH->filename, $tgt_file ); require Digest::MD5; my $md5; $FH->seek(0,0); $md5 = Digest::MD5->new->addfile( $FH ); print 'by FH: ',$md5->hexdigest,"\n"; my $md52; open(FILE, $tgt_file) or die "Can't open : $!"; binmode(FILE); $md52 = Digest::MD5->new->addfile(*FILE); close FILE; print 'by FILE1: ',$md52->hexdigest,"\n"; my $md53; open(FILE, $FH->filename) or die "Can't open : $!"; binmode(FILE); $md53 = Digest::MD5->new->addfile(*FILE); close FILE; print 'by FILE2: ',$md53->hexdigest,"\n";

In reply to binmode layer and seek by ftumsh

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.