XP is just a number | |
PerlMonks |
Re: File splitting helpby monarch (Priest) |
on Jan 20, 2009 at 21:47 UTC ( [id://737695]=note: print w/replies, xml ) | Need Help?? |
You possibly want to investigate the use of the seek or sysseek functions.
Either way you're going to have to read chunks of data and write chunks of data. Suggestion, then: use read or sysread to pull in large chunks of the file at a time, say 64 kilobytes, into a buffer. Keep a counter of what position you are in the file. Write that buffer to your chunk file, however if the counter exceeds your chunk length (e.g. 400MB) then scan backwards for the last newline character using rindex. Flush the initial portion of that buffer, then close your file, and flush the last portion of that buffer to a new chunk file, reset your chunk length counter, and continue. Some psuedo-code (this is _not_ Perl):
Update: had to ensure read was to end of buffer, close chunk file when done
In Section
Seekers of Perl Wisdom
|
|