in reply to count lines, bottom to top
There is a way to open a file for both reading and writing (see the description of open), however, I've never used it (and a read|write open will not, according to the docs, usually work on text files). When I need to do this, I tend to use Tie::File.
One obvious thing to try is to explicitly set $count to 0 ( ($count = 0;) before starting to count the
lines which are more recent than $oldest_time. Also, you may be better off using (as you said)
foreach reverse @lines
or
while(@lines){ $timestamp = pop(@lines);
My tendency is to prefer the latter (but not when using Tie::File!). I think the reverse will create a temporary array, while nibbling away at the end doesn't. If the files are very large, you may need to use Tie::File or File::ReadBackwards.
emc
Experience is a hard teacher because she gives the test first, the lesson afterwards.
|
|---|