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

Is it possible to have a script do a cearting action like
reading and wrting from and to a file every 5 minutes?
If so, how would I go about acomplishing this task?
Jemts

"If you're traveling in a time machine, and you're eating corn on the cob, I don't think it's going to affect things one way or the other. But here's the point I'm trying to make: Corn on the cob is good, isn't it."
  • Comment on A script that does an action every 5 minutes

Replies are listed 'Best First'.
Re: A script that does an action every 5 minutes
by TStanley (Canon) on May 26, 2001 at 00:53 UTC
    Put your action in a loop and include this statement: sleep(300) as part of the loop.
    So your overall code might look like:
    while(condition){ ## code here if(exit condition){ ## code here }else{ sleep(300); } }
    At least this is what I am assuming from your question.

    TStanley
    --------
    There's an infinite number of monkeys outside who want to talk to us
    about this script for Hamlet they've worked out
    -- Douglas Adams/Hitchhiker's Guide to the Galaxy
      I like until for doing that:
      until ( $to_sleep_perchance_to_dream ) { print scalar localtime, "\n"; sleep 300; }

      ar0n ]

Re: A script that does an action every 5 minutes
by arturo (Vicar) on May 26, 2001 at 00:58 UTC

    In all likelihood, the best tool for this sort of job is a system utility like cron (installed on all *nix systems) or Windows' "Task Scheduler".

Re: A script that does an action every 5 minutes
by mikeB (Friar) on May 26, 2001 at 01:52 UTC
    If you're on Win32 (NT, 98, etc), check out Win32::AdminMisc on CPAN. It has functions which allow adding jobs to the "crontab" (AT list). You can use Perl to schedule your Perl script :-)