Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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; }

Comment on Read log which is being updated continuisly
Download Code
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.
      but OP isn't using the <> operator, op is using the read method, straight from the synopsis
      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 "$_"; }
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994616]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (16)
As of 2014-07-14 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (259 votes), past polls