Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Reading from an appended file

by Lhamo_rin (Friar)
on Oct 17, 2005 at 13:31 UTC ( [id://500718]=perlquestion: print w/replies, xml ) Need Help??

Lhamo_rin has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I have a file that is being appended every 10 minutes. I am trying to read from it at the same rate but only want to read the additional information that is being appended, I don't want to read the whole file each time I try to access it. How can I do this?

Replies are listed 'Best First'.
Re: Reading from an appended file
by Zaxo (Archbishop) on Oct 17, 2005 at 13:38 UTC

    Once you reach the end of the file, you can call tell to get the offset to eof. Then when you reopen the file, seek to that point and read on. Assumes your program runs continuously. Store the value somewhere if not.

    After Compline,
    Zaxo

Re: Reading from an appended file
by marto (Cardinal) on Oct 17, 2005 at 13:39 UTC
    Hi Lhamo_rin,

    The module File::Tail may be of use to you.
    You can set an interval of 600 seconds so that the file would be read every 10 minutes for new lines.

    Hope this helps.

    Martin
Re: Reading from an appended file
by blazar (Canon) on Oct 17, 2005 at 13:39 UTC
    This is another faq in just a few minutes. Well, sort of: in any case you may be interested in checking what perldoc -q tail has to tell you. To quote from it:
    First try seek(GWFILE, 0, 1); The statement "seek(GWFILE, 0, 1)" doesn't change the current position +, but it does clear the end-of-file condition on the handle, so that the next <GWFILE> makes Perl try again to read something.
Re: Reading from an appended file
by gopalr (Priest) on Oct 17, 2005 at 13:44 UTC

    Hi

    Please take a look at File::Slurp Module.

    use File::Slurp; use strict; my $text = read_file( 'de.txt' ) ;

    Thanks
    Gopal.R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-19 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found