Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Think about Loose Coupling
 
PerlMonks  

Re: Sorting Dates

by demerphq (Chancellor)
on Nov 24, 2005 at 07:20 UTC ( [id://511419]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Sorting Dates

If you can then ditch the unsortable date format. Otherwise just transform the date before the sort and use the ISO format internally. Using non ISO compliant dates in computer software is inherently evil so doing this will be a net improvement (IMO) to your code. The sooner these regional date formats go the way of the steam engine the better. Something like the following regex should do it:

s!(\d+)/(\d+)/(\d+)!sprintf"%04d-%02d-%02d",$3,$2,$1!e;

With this representation used internally you can use lexicographical sorting on the keys of the hash. Ie:

my @sorted=sort keys %hash;

Alhough even here you are introducing year 10000 incompatibilities. If that worries you then you should use some other technique like the Swartzian Transform. Me, I tend to think that if they are still using my code 7000 years from now they deserve what they get.

---
$world=~s/war/peace/g

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://511419]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.