> 
> without using 'tail' how can I get the trailing 5 lines of a 
> large file
> quickly, without loading it all to memory?
> 
> is there anyway without pop and shifting through an array 
> foreach line? (<=
> 

somebody posted this code last week, which gets the last line of the file
--
open F, "file.txt" or die $!;
seek F, 0, 2;
while ($pos = tell F) {
        seek F, -($pos > 1024 ? 1024 : $pos), 1 or die;
    read F, $block, 1024;
    $_ .= $block;
    do {$last = $1; print "$last"; last} if /.+\n(.+)/s;
}

---
the part I am not sure about is the do block ( i never use them). This works
for getting last line, so it should not be too hard to change it to  get the
last 5 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to