i recently encountered a problem about something that should be really easy but in fact i couldn't find any information on how to do it.
what i want to do is read a logfile in perl. i open the file, read the data, parse it, then close the file. so far so good.
now, while the script is running, i append a few lines to the logfile. i now want perl to somehow remember at which line it last read, and when i open the file i want to jump to the end and read only the new lines.
the reason for this is that i might have huge logfiles and reading them completely all the time won't work fast enough.
Expand|Select|Wrap|Line Numbers
- $exitfile = '/path/to/the_exit_file';
- while (!(-e $exitfile)) {
- print "and we read?\n";
- open(DAT, "/path/to/mylog.log") || die("Could not open file!");
- foreach $line (<DAT>) {
- chomp($line);
- print $line;
- }
- close(DAT);
- sleep(1);
- }
anyone know how i can just read the new lines?
what i was thinking was counting the lines in my foreach loop, but then i have the problem of not being able to move my pointer to that location.
thanks!