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

I have an html form that will take an integer and add it to a single integer in a .txt whenever a user enters a number and clicks submit. Next I want to plot this data on bar graph that will display the current running total for the day, the total for the past 7 days and the current running total for the month and year.

Is Schedule::Cron applicable? Running this every day at 00:00:00 seems like the solution. Any suggestions on a better one? I think this works, but I'm not sure if it's the best approach. I'm also not familiar with Schedule::Cron at all.

Replies are listed 'Best First'.
Re: Running a script daily
by jethro (Monsignor) on Aug 19, 2010 at 16:10 UTC

    Are you on linux or something unixoide? In that case there is a cron daemon already running on your system. Why start another one?

      Are you on linux or something unixoide? In that case there is a cron daemon already running on your system. Why start another one?

      Well the issue is that I don't even know how to implement this. I want to update the .txt at midnight everyday and then produce a new bar graph or chart of the data.

        Short intro to cron. Call cron with this on the command line (as the user who should run the script):

        export EDITOR=emacs crontab -e

        Substitute 'emacs' with your favourite editor if you like

        Then your editor should start and you can input a line

        0 0 * * * script.pl

        The first 0 means minute, the second hour. The next fields are day of month, month and day of week, and a '*' is equivalent to 'any'. So it is 0:00 of any day in any month and any day of the week.

        Save and from then on cron will call your script.pl every night at 12

Re: Running a script daily
by Jason Hutchinson (Acolyte) on Aug 19, 2010 at 17:01 UTC
Re: Running a script daily
by alexbio (Monk) on Aug 19, 2010 at 16:13 UTC

    I'm not sure I've understood what you need: do you need just to run a script daily? If so, and if you are on a Unix-based system, why not using cron(8) instead, which is a standard administration tool? You won't need to mess with Schedule::Cron

    Please correct me if I misunderstood your need.

    Update: Ooops, didn't notice the post above.

    Alessandro Ghedini <http://ghedini.co.cc>
Re: Running a script daily
by dasgar (Priest) on Aug 19, 2010 at 18:37 UTC

    I agree with what some of the others are suggesting. First, write the script that does the work you want without worrying about the scheduling part. Then after getting that running correctly, use your OS's scheduler (cron in *nix, Task Scheduler in Windows) to run the task every day at midnight.

    (If you're like me and not very familiar with cron, it looks like jethro gave you some tips on how work with cron.)

      Agree with all the above postings. My additional thought would be to stay away from any boundary condition that might either be confusing or potentially produce erroneous results.

      The date changes at 00:00:00 (midnight), but sometimes 24:00:00 is used to mean the same time but with the date before. A time like 2:00 AM local can be trouble too as 2 AM can occur twice when this daylight savings time "go backwards" stuff happens. I often pick a number like 3:19 AM or 4:43 AM for these chron or task scheduler jobs for the simple reason of avoiding these issues.