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

I have a pipe delimted text file. I use a split to get the date from each record in the file. So now something like $split_result[3] is equal to a text string like 02/24/2002.

I now want to compare that $split_result[3] to the current date.

Any suggestions on an approach would be appreciated.

Edit by tye to preserve paragraphs and since single-word titles complicate future simple searches

Replies are listed 'Best First'.
Re: date
by particle (Vicar) on Mar 01, 2002 at 18:03 UTC
    look here on the site: date
    or here on cpan: date

    there are many ways to do this, and plenty of good documentation for comparing dates.

Re: Compare MM/DD/YYYY to current date
by jlongino (Parson) on Mar 01, 2002 at 21:43 UTC
    Here is a subroutine that I believe is attributed to Christian Murphy (r1938c@email.sps.mot.com). The only thing I modified was to change the yyyy_mm_dd format to yyyy/mm/dd.
    use strict; my $datestr = yyyymmdd(time); print "$datestr\n"; sub yyyymmdd { #----------------------------------------------------------------- +------ # yyyymmdd -- given a clocktime (in seconds since the epoch), retu +rn the # corresponding date in the format "yyyy/mm/dd" # # usage: $date = &yyyymmdd($clocktime); #----------------------------------------------------------------- +------ my ($clocktime) = @_; my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime($clocktime); $mon ++; ($year += 1900) unless (length($year) == 4); ($mon = "0$mon") unless (length($mon) == 2); ($mday = "0$mday") unless (length($mday) == 2); return $year . "/" . $mon . "/" . $mday; }

    --Jim

    Update: I realize this isn't the format you're using, but you should be able to modify it for your purposes. I also eliminated some code that didn't pertain to your question.