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

Hi,

I'm wondering if there is a way that I can make different things happen based on the time, and if anyone could explain to me how I would do this? For example, to have a certain piece of code run on Christmas, Halloween, etc.

Thanks,
Spidy

Replies are listed 'Best First'.
Re: Time-Based Conditionals?
by jaldhar (Vicar) on Aug 27, 2004 at 16:37 UTC
Re: Time-Based Conditionals?
by doowah2004 (Monk) on Aug 27, 2004 at 17:02 UTC
    You could set up a cron job to run the script on the given day.

    Or if you do not mind having a perlscript always running, you can use select() to pause the script, then check to see what day it is.

    select( undef,undef,undef,86400);

    would pause for 1 day (60 * 60 * 24)s in a day.

    Date::Calc is good for calandar manipulations.

      This is assuming that I'm using CGI, and printing out some html. I'm trying to figure out a way to have it print out code on a certain day, for example October 12th. How would I first check to see what day/time it was, and then do something based on the code? I'm fairly certain that doing something would just be a simply matter of putting something inside the conditional, but..?

        See localtime() or gmtime(). You could compare the results of the returned array to some parameters.

        --MidLifeXis