in reply to Split file into 4 smaller ones
use the -s operator to determine the file's size, and set the $/ special variable to equal 1/4th of the size returned by -s. Then read in a while() loop, just like you always would.
See perlvar for an explanation of how to set $/, and perlfunc -X to learn about -s
...or, again use -s, and then seek to specific locations and use sysread with a length of 1/4th of the total. But then beware of off-by-one errors.
Of course with any of these methods, you're going to run into some memory constraints; reading 25% of a 10GB file will consume 2.5GB. Might be better to set $/ to 1/16th of the file size, and then read/write four times for each output file.
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Split file into 4 smaller ones
by Anonymous Monk on Feb 08, 2013 at 08:43 UTC |
In Section
Seekers of Perl Wisdom