For the chunk size parameter , you can specify megabytes or gigabytes. Here is an example on how the script can be runned:

perl split.pl linux.iso 100M linux_chunks

where linux.iso is a cd image we're splitting in 100MB chunks , and we're storing them in the directory linux_chunks. Hope this helps !
use strict; use warnings; my $f=shift || die "File that your want to split\n"; my $chunk_size=shift || die "Chunk size\n"; my $dir=shift || die "Directory where the chunks are stored\n"; my $fsize=-s $f; my $size=0; my $buffer; my $BUFFER_SIZE=4096; my $nr_of_chunks=0; my $nr=0; if($chunk_size=~/(\d+)([mMgG])/) { my $numb=$1; my $tp=$2; SW: { ($tp eq "g" || $tp eq "G") && do { $numb*=1024*1024*1024; $size=$numb; last SW; }; ($tp eq "m" || $tp eq "M") && do { $numb*=1024*1024; $size=$numb; last SW; }; } } else { $size=$chunk_size; } open(F,$f) || die "OPEN : $!\n"; binmode(F); if(! -e $dir) { mkdir($dir) || die "DIR : $!\n"; } chdir($dir) || die "CHDIR : $!\n"; FILE:{ if(($fsize - $size)<=0) { my $count=0; print "Creating file $nr\n"; open(C,">$nr") || die "CREATE : $!\n"; binmode(C); while($count != $fsize) { $count+=read(F,$buffer,$BUFFER_SIZE); print C $buffer; } close C; last FILE; } else { my $count=0; print "Creating file $nr\n"; open(C,">$nr") || die "CREATE : $!\n"; binmode(C); while($count != $size) { $count+=read(F,$buffer,$BUFFER_SIZE); print C $buffer; } close C; $fsize-=$size; $nr++; redo FILE; } } print "Over & Out\n";
and the script needed to join the files
use strict; use warnings; my $dir=shift || die "Directory where the chunks are stored\n"; my $out=shift || die "Name under which we join the chunks\n"; my @files; my $buffer; opendir(D,$dir) || die "OPENDIR : $!\n"; @files=grep { /^\d+$/ } readdir(D); closedir(D); chdir($dir) || die "CHDIR : $!\n"; open(F,">../$out") || die "CREATE : $!\n"; binmode(F); @files=sort { $a <=> $b } @files; for(@files) { open(C,$_) || die "OPEN : $!\n"; binmode(C); while(read(C,$buffer,4096)) { print F $buffer; } print "I joined chunk nr. $_\n"; close C; } print "File $out is complete now\n"; close F;

In reply to File splitting script by Alien

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.