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;