[tpm] Question of the day

Digimer linux at alteeve.com
Wed Mar 17 11:11:42 PDT 2010


'Alo all,

I need to "tail -f" a file, and I've accomplished that using this:

my $log_file="/some/file.txt";
my $read=IO::Handle->new();
open ($read, "<$log_file") || die "Failed to open log file: [$log_file], 
error: $!\n";
# while (<$read>)
for (;;)
{
	my $curpos;
	for ($curpos = tell($read); <$read>; $curpos = tell($read))
	{
		# search for some stuff and put it into files
		chomp;
		print "line: [$_]\n";
	}
	# sleep for a while
	sleep 1;
	seek($read, $curpos, 0);  # seek to where we had been
}

That's pretty much verbatim from the FAQ, but it's a resource hog, 
relatively speaking. Is there way to make the loop event driven by chance?

Basically, I need to watch a log file and update a database when an 
entry is written. To complicate matters, the log file is cycled each 
night, so it would need to be able to handle the position being reset to 0.

Thanks all!

-- 
Digimer
E-Mail:         linux at alteeve.com
AN!Whitepapers: http://alteeve.com
Node Assassin:  http://nodeassassin.org


More information about the toronto-pm mailing list