hi all,
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.
in this case, i keep opening the file every second and reading it all the way through until i create a certain file (the exit file)
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!
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.
Code:
$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!
Comment