http://www.perlmonks.org?node_id=863112

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

Hi Monks! I'm having trouble trying to compare 4 dates. Each row of data that i have contains 4 dates and i need to compare them and print the order. I have some sample code below.

#!/usr/bin/env perl use warnings; use strict; use Data::Dumper; use Date::Manip; my $flag; my $jim; my $bob; while (<DATA>) { if ( $. == 1 ) { print; next; } my $aref = [split /~/]; #print "JIM is $aref->[1], BOB is $aref->[2]\n"; $flag = Date_Cmp($aref->[1],$aref->[2]); if ($flag) { $jim = '1'; $bob = '2';} else { $bob = '1'; $jim = '2';} print "$aref->[0] $jim $bob\n"; } __DATA__ EVENT JIM BOB SAM JACK PTRED~09/29/10 03:23:05 PM ~09/28/10 02:21:09 PM ~09/26/10 11:00:03 AM + ~09/27/10 09:33:41 PM RED~08/29/10 01:55:00 AM ~08/30/09 12:10:10 PM ~08/27/10 08:16:21 PM ~ +09/01/10 12:12:12 AM INT~07/04/10 03:21:15 AM ~07/08/10 04:17:33 PM ~06/30/10 04:22:11 AM ~ +06/28/10 10:11:01 PM PTRED~06/19/10 09:19:55 PM ~04/25/10 07:39:22 PM ~09/16/10 10:34:24 AM + ~07/22/10 06:19:38 PM RED~04/29/10 12:10:59 AM ~04/20/10 02:13:33 AM ~07/17/10 01:00:05 PM ~ +09/01/10 11:10:15 PM INT~05/23/10 11:11:11 PM ~01/08/10 10:45:12 PM ~05/15/09 03:29:37 AM ~ +05/18/09 12:59:59 PM

For the purposes of this question i added the __DATA__ but date_cmp doesn't seem to recognize the date format when i do this. When i actually return the dates from oracle and compare 2 dates date_cmp works fine. I'm explaining this because the real issue is that i'm struggling with the concept of how to compare 4 dates..not that __DATA__ doesn't recognize the date formats i added for this sample. The goal is to print output as follows:

EVENT JIM BOB SAM JACK PTRED 4 3 1 2 RED 3 1 2 4 INT 3 4 2 1 PTRED 2 1 4 3 RED 2 1 3 4 INT 4 3 1 2

Any help provided will be mucho appreciated! Thanks Tony