Re: Read only the last line of a file??
- --- In perl-beginner@y..., "Chirhart, Brian" <bchirhart@f...> wrote:
> Is it possible to only read in the last line of a file - a log file forIn the thread (viewable at: http://groups.yahoo.com/group/perl-beginner/message/8926):
> example? I want to parse the LOG's that a program makes, but they can get
> pretty large and there are a LOT of them. I only need the information on
> the last line. Any clues?
> The only way I know how to open a file is with:
> open (LOG,$_) ||
> die "Sorry - Died: $!";
> #Code here....
> But that opens and examines the entire LOG file. Any help would be
Another user asked a similar question, and Jahpy suggested using the File::ReadBackwards module for a pre-written implementation of reading the file backwards.
Using that module, you just read one line (which will be the one at the end of the file), and process that.
BTW: Your example above opens "LOG" (which is never closed), and closes "CFG" (which is never opened).