[comp.lang.perl] comparing dates...

cwilson@NISC.SRI.COM (Chan Wilson) (06/28/90)

Since there appear to be people out there who delight in finding
ways of 'elegantly' doing things in perl...

I've got dates, in the form of 'Jun 27 04:11:47' that I need to 
compare to each other. (ala $date1 lt $date2, which won't work). 
Has someone come up with a fairly easy solution to this?  

Thanks..

--Chan
			   ................
    Chan Wilson -- cwilson@nisc.sri.com <!> I don't speak for SRI.
Janitor/Architect of comp.binaries.apple2 archive on wuarchive.wustl.edu
			      "a2fx it!"
			   ................

merlyn@iwarp.intel.com (Randal Schwartz) (06/28/90)

In article <18107@fs2.NISC.SRI.COM>, cwilson@NISC (Chan Wilson) writes:
| Since there appear to be people out there who delight in finding
| ways of 'elegantly' doing things in perl...
| 
| I've got dates, in the form of 'Jun 27 04:11:47' that I need to 
| compare to each other. (ala $date1 lt $date2, which won't work). 
| Has someone come up with a fairly easy solution to this?  

Something like this?

%monthmap = split(/(\d+)/, <<EOS);
Jan01Feb02Mar03Apr04May05Jun06Jul07Aug08Sep09Oct10Nov11Dec12
EOS

sub compare_dates { #
	local(@dates) = @_;
	local($[,$_) = 0;
	for (0..1) {
		$dates[$_] =~
		s/^(...) (\d\d) (\d\d):(\d\d):(\d\d)/$monthmap{$1}$2$3$4$5/;
		print "$_ is $dates[$_]\n";
	}
	$dates[0] - $dates[1];
}

print &compare_dates('Jun 27 04:11:47','Jul 09 11:22:33');

print q/Just another Perl hacker,/
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/