Testing on non-CygWin (Activestate Win32), trying to replicate the possible test/binary condition. This (highly refactored) code, when reading and writing binary (raw), works perfectly. Changing the output mode back to Text reproduces the behaviour described in the OP.

use strict; use warnings; my $self = { data => 'PM_618194_in.dat', process => 'patient' }; my $config = { blocksize => 550, startblock => 3 }; my $max_chunk_size = 1_000_000; my $chunk_size = int( $max_chunk_size / $config->{blocksize} ) * $config->{blocksize} ; open my $parent_fh, '<:raw', $self->{data} or die "Cannot open '$self->{data}' for incremental parsing: $!"; my $bytes_read = read $parent_fh, my $junk, $config->{startblock}; if ( $bytes_read != $config->{startblock} ) { warn "Tried to read $config->{startblock} bytes, ". "but got $bytes_read bytes!\n"; } $/ = \$chunk_size; # Set <> for fixed blocksize reads. my $file_num; while ( <$parent_fh> ) { $file_num++; my $filename = sprintf 'tmp/%s%02d.dat', $self->{process}, $file_num; open my $out_fh, '>:raw', $filename # open my $out_fh, '>', $filename or die "Cannot open '$filename' for incremental writing: $!"; print $out_fh $_ or warn; close $out_fh or warn; } close $parent_fh or warn;
BTW, you can save yourself a good bit of code by factoring out the {startblock} read, and using $/, as I have above. Also, when your files are binary, it is *always* most correct to use binary mode, even when your OS (like Unix) does not care.


In reply to Re: Unexpected File Results by Util
in thread Unexpected File Results by Grundle

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.