in reply to Re: Chunking very large files
in thread Chunking very large files

You're right in that the final version will have a fixed chunk size. This is simply an exercise to figure out if I can do it or not, and then I'll change the code accordingly.

I am not very experienced with buffers, and the code I pasted is from an earlier answer on perlmonks to a very similar question that I asked, only they were dealing with smaller files. I'll see if I can figure out how to adjust the loop and use fixed chunk sizes.

Thanks for your advice.

Replies are listed 'Best First'.
Re^3: Chunking very large files
by SuicideJunkie (Vicar) on Nov 09, 2011 at 20:07 UTC

    Should be as simple as:

    my $sizeRead = $chunkSize; while ($sizeRead == $chunkSize) { $sizeRead = read $in_fh, $buffer, $size; die "Error reading: $!\n" unless defined $sizeRead; ... }

      What about the end of the file where $sizeRead will be smaller than chunkSize?

        In that case, $sizeRead will be smaller than $size. Possibly zero if your file is exactly a multiple of the chunk size. You then write the chunk as normal (unless its size zero), and the while loop exits.