http://qs321.pair.com?node_id=1197028


in reply to how to populate array with last 20 lines of file

I don't know if this is the "best" way, but one route would be to use Tie::File. It basically "represents a regular text file as a Perl array". And since it does not store the entire file into memory, you can use this for large files without major concern about memory usage - although the 8KB size you mentioned in another post isn't too big to store in memory.

If you use Tie::File, grabbing the last 20 lines is simply grabbing the last 20 elements of the array.

  • Comment on Re: how to populate array with last 20 lines of file

Replies are listed 'Best First'.
Re^2: how to populate array with last 20 lines of file
by ytjPerl (Scribe) on Aug 08, 2017 at 19:51 UTC
    Hi, Thanks for your posting. The major concern of not using the whole file is not because of memory issue. I need to find a string in that file to determine whether application is running or not. If I restart the application multiple times, there will be multiple 'startup' string in this log, so that I only need last lines of the log when its size is not increasing anymore.