in reply to breaking up very large text files - windows
Another way of doing it is going through your big file and filling an array of (say) 1000 lines (or as many as you would like to keep) replacing the oldest lines by newer lines in a round-robin-type of fashion. At the end of the big file you have your 1000 lines in the array.
If you don't know beforehand how long the lines are, I think it is the best and fastest way of doing it (you don't have to read in your big file twice as you did), with the exception perhaps of the modules already suggested.
Update: As a matter of fact this is the way the Perl Power Tools tail-function works also (but it has a lot more options, which you perhaps do not need) and hereafter follows the relevant code from the Power Tools (slightly adapted):
$fh is the filehandle to your big file and $p is the number of lines you needwhile(<$fh>) { $i++; $buf[$i%($p)] = $_; } my @tail = (@buf[ ($i%($p) + 1) .. $#buf ], @buf[ 0 .. $i%($p)]); for (@tail) { print if $_; }
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
|
|---|