Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Need help comparing 4 dates

by jwkrahn (Monsignor)
on Oct 03, 2010 at 05:08 UTC ( #863143=note: print w/ replies, xml ) Need Help??


in reply to Need help comparing 4 dates

This appears to work:

#!/usr/bin/perl use warnings; use strict; my @headers; while ( <DATA> ) { if ( $. == 1 ) { print; @headers = split; next; } chomp; my %data; @data{ @headers } = split /\s*~\s*/; for ( @data{ @headers[ 1 .. $#headers ] } ) { my ( $mon, $day, $year, $hour, $min, $sec ) = /\d\d/g; $hour += 12 if /PM/i; $_ = join '', $year, $mon, $day, $hour, $min, $sec; } my $new_order = 1; my %ordered = ( @headers[ 0, 0 ], map { $headers[ $_ ], $new_order++ } sort { $data{ $headers[ $a ] } <=> $data{ $headers[ $b ] } } 1 .. $#headers ); printf "%-7s %-7s %-7s %-7s %-7s\n", @ordered{ @headers }; } __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


Comment on Re: Need help comparing 4 dates
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-20 15:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls