if new file
{
read all lines and insert into db.
current_line is the last line
} else if not new file
{
go to current_line
read all new lines and insert into db
}
Any thoughts on this? Thanks.
If the file does not get altered for a while, File::Tail gets suspicious and starts checking if the file was truncated, or moved and recreated. If anything like that had happened, File::Tail will quietly reopen the file, and continue reading. The only way to affect what happens on reopen is by setting the reset_tail parameter (see below). The effect of this is that the scripts need not be aware when the logfiles were rotated, they will just quietly work on.So I would say the answer to that question is yes :)
The other solutions are good, but your pseudocode suggests that you're looking for the functions seek() and tell(). Augmenting your pseudocode a little:
if new file
{
# read all lines and insert into db.
# Save current position for next time...
$current_line = tell(FH);
} else if not new file
{
# Go to current line
seek(FH,0,$current_line);
# read all new lines and insert into db
# Save position for next iteration...
$current_line = tell(FH);
}
--roboticus
perlmonks.org content © perlmonks.org and McDarren, perlknight, roboticus, srdst13
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03