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

How to read a file after a certain interval continuously

by ghosh123 (Monk)
on Feb 08, 2013 at 04:41 UTC ( [id://1017757]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monk,

Suppose I am reading a text file in my perl script which is continuously getting updated.
How can I read that text file after a particular time (in every 5 or 6 mins) continuously so that my code automatically parses the updated text file.

Thanks.

Replies are listed 'Best First'.
Re: How to read a file after a certain interval continuously
by mhearse (Chaplain) on Feb 08, 2013 at 06:02 UTC
    Use cron to schedule you script. You can save the line number of the last run. Seek to that line number. And read until EOF.
Re: How to read a file after a certain interval continuously
by vinoth.ree (Monsignor) on Feb 08, 2013 at 04:47 UTC

    Please check this module File::Tail

    File::Tail - Perl extension for reading from continuously updated files

      I have checked that module. But actually my job is not only file parsing after every interval, the operation could change later.

      I need a timer basically, so as to carry out any operation (for example file parsing, running some function) after an interval automatically. .

        I have checked that module.

        You could have told that in your first post:). No Problem.

        read perl alarm.alarm and also check this module Sys::AlarmCall

Re: How to read a file after a certain interval continuously
by muba (Priest) on Feb 08, 2013 at 09:35 UTC

    One of many approaches would be to do it like this:

    my $interval = 60 * 5 # seconds * minutes my $run_when = time + $interval; while (1) { # ... if (time - $run_when <= 0) { do_the_stuff; $run_when = time + $interval; } }
Re: How to read a file after a certain interval continuously
by zentara (Archbishop) on Feb 08, 2013 at 10:31 UTC
Re: How to read a file after a certain interval continuously
by MidLifeXis (Monsignor) on Feb 08, 2013 at 13:38 UTC

    Does the file ever get rolled (renamed to $file.bak and a new $file created - .bak is just an example, could be numbered or dated backups as well)? If so, you will have to deal with the logic of parsing the remains of the old file and then starting at the beginning of the new file as well.

    --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1017757]
Approved by vinoth.ree
Front-paged by MidLifeXis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-03-19 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found