If you want to have a program sleep, and then run something every 15 minutes, you could write:
use strict; # Loop forever while(1) { some_function(); another_function(); # Sleep statement, in seconds # 15 minutes * 60 seconds in a minute = 900 seconds sleep 900; } sub some_function { foo; bar; } sub another_function { yada_yada; wocka_wocka; }
However, I am the type who would absolutally prefer to use cron to handle timing, as opposed to Perl. Cron is a wonderful resource, and I find it easier to use an existing resource then to recreate one. It's one thing if you will always stick to 15 minutes.. but what if you ever decide you don't want it to run on the weekends?

Secondly, by having your Perl program handle the time -- if you ever reboot, you'll need to rerun the program. Or create a startup script to do it for you. What if you end up with 15 of these scripts? Or 50? I would personally find it much easier to manage them with cron.

Lastly, a point could be raised about system resources. Having scripts running all the time uses memory. It may be easier on your system resources to have them only run when necessary. The other side of the coin is that depending on the script, it might take a lot of CPU time to fire up that script every 15 minutes, instead of leaving it in RAM where the system may cache it. But you'll have to do some benchmarks to work that out :-)
-Eric

In reply to Re: cron or perl? by andreychek
in thread cron or perl? by blax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.