Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Read log which is being updated continuisly

by bimleshsharma (Beadle)
on Sep 20, 2012 at 09:25 UTC ( #994616=perlquestion: print w/replies, xml ) Need Help??
bimleshsharma has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to read log of server which is being updating continuously. I tried below code but i dont see output.Thanks in advance

use File::Tail; my $file = File::Tail->new("/some/log/file"); while (defined(my $line= $file->read)) { print $line; }

Replies are listed 'Best First'.
Re: Read log which is being updated continuisly
by Arunbear (Parson) on Sep 20, 2012 at 11:13 UTC
    You may need to adjust the parameters you pass to new(). E.g. with
    perl -MFile::Tail -E '$f = File::Tail->new(q[/var/log/foo/bar.log]); p +rint $l while $l = $f->read'
    I had to wait 9 seconds before output was produced. But with
    perl -MFile::Tail -E '$f = File::Tail->new(name=> q[/var/log/foo/bar.l +og], tail=>10, maxinterval=>0.5); print $l while $l = $f->read'
    The output appears right away.
Re: Read log which is being updated continuisly
by nemesdani (Friar) on Sep 20, 2012 at 09:34 UTC
    You must tie() your filehandle, thus the <> operator won't return an undef.

    I'm too lazy to be proud of being impatient.
      Yes you are right but File::Tail->read has capability to read file. Anyway i tried below but still not success.
      use File::Tail; my $name="/some/file/toread/"; my $ref=tie *FH,"File::Tail",(name=>$name); while (<FH>) { print "$_"; }
      but OP isn't using the <> operator, op is using the read method, straight from the synopsis

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994616]
Approved by Corion
[robby_dobby]: shmem:everything2
robby_dobby says Sorry and points to his boredom
[shmem]: robby_dobby: since everything is everything, it is thus also everything2. And everything2 is based on... you name it.
[Corion]: Mhhmmm. I just had to remind two contractos of their priorities from my point of view. This felt somewhat like getting my godson+siblings to clean their room, including the evil eye I threw them ;)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2017-04-25 13:31 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (454 votes). Check out past polls.