[ale] stupid perl question
Chris Fowler
cfowler at outpostsentinel.com
Thu Jun 23 19:27:18 EDT 2011
On Thu, 2011-06-23 at 16:02 -0700, Steven A. DuChene wrote:
> I am attempting to do a "tail -f" on a log file that has a new line added to it every 15 seconds.
> I need to parse and process each new line as it is added to the file.
>
> I am trying to use the following example code from cpan to see if the basic concept will
> work using File::Tail but when I run the example code below and add lines to the file
> I get nothing out.
>
> #!/usr/bin/perl
>
> use File::Tail;
> $file = File::Tail->new("/home/sad/bin/power_input_stuff.txt");
> while (defined(my $line = $file->read))
> {
> print $line;
> }
>
try adding '$|;' above the while statement.
File::Tail probably implements all the logic of tail but I typically use
tail
$|;
open F, "tail -f file |";
while(<F>) {
print $_;
}
You can also implement some of your own logic.
$|;
open F, "< file.txt";
while(1) {
# Check for possible truncation by logrotate!
while(<F>) {
print $_;
}
sleep 10;
}
More information about the Ale
mailing list