Sample code for 30+ languages & platforms
Perl

Split File into Chunks

Demonstrates how to split a file into chunks.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $fac = Chilkat2::FileAccess->new;

# Any type of file may be split.  It doesn't matter if it's
# a binary file or a text file.
my $fileToSplit = 'qa_data/hamlet.xml';

my $partPrefix = 'hamlet';
my $partExtension = 'part';
my $maxChunkSize = 50000;
my $destDirPath = 'qa_output';

# Splits hamlet.xml into hamlet1.part, hamlet2.part, ...
# Output files are written to the current working directory.
# Each chunk will be 50000 bytes except for the last which
# will be the remainder.
my $success = $fac->SplitFile($fileToSplit, $partPrefix, $partExtension, $maxChunkSize, $destDirPath);

if ($success) {
    print "Success.\n";
} else {
    print $fac->LastErrorText, "\n";
}