in reply to splitting a file
I don't see why not. Following is one possible way. This should break up your 8 GB file into 512 MB files 1 MB at a time. It's untested as I don't have an 8 GB file handy, but should give you the idea.
my $filename = 'foo'; my $bufferSize = 1,000,000; my $outFileSize = 512; open (IN, $filename); binmode IN; seek (IN, 0, 0); my $buffer; my $i = 1; my $j = 1; open (OUT, "$filename$i"); while (read (IN, $buffer, $bufferSize)){ if ($j > $outFileSize){ $j = 1; $i++; close OUT; open (OUT, "$filename$i"); } print OUT $buffer; $j++; } close OUT;
UPDATE: No I don't manufacture hard drives, so as Fletch correctly points out, $bufferSize should be 1048567 bytes. Oh, and leave out the commas.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting a file
by Fletch (Bishop) on Jul 05, 2007 at 12:47 UTC |