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

Hello monks...could someone offer me wisdom?
I am trying to write a script that does a check at the beging to see if it is the first tuesday of every month.
So:
$day = tuesday;
$date <= 7;
if both of those hold true go on with the script if not die does anyone know do this?
Thanks a bunch.
mrbbq

Replies are listed 'Best First'.
Re: Date and Time
by tcf22 (Priest) on Oct 28, 2003 at 21:34 UTC
    Use localtime.
    #All the values you can get if you need them #my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = # localtime(time); my ($mday,$wday) = (localtime())[3,6]; die unless($wday == 2 && $mday <= 7);

    - Tom

Re: Date and Time
by hardburn (Abbot) on Oct 28, 2003 at 21:29 UTC

    See Date::Calc, which has a subroutine Nth_Weekday_of_Month_Year() that does what you need.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

Re: Date and Time
by Paulster2 (Priest) on Oct 29, 2003 at 01:04 UTC

    While above suggestions are great, check out the Date::Manip module, as it will do anything with just about any type of date or time or weekend or ... take a look, it's awesome.


    Paulster
Re: Date and Time
by Art_XIV (Hermit) on Oct 28, 2003 at 21:40 UTC

    I'm not trying to be a wise-acre, just I'm assuming that this is a syntax question:

    use strict; my $day = 'wed'; my $date = 1; ($day eq 'tuesday' && $date <= 7) or die "Barf!\n"; print "Script completed.\n";
Re: Date and Time
by mrbbq (Sexton) on Oct 28, 2003 at 22:34 UTC
    Thanks everyone....problem solved.
      What (how did you solve the problem)?