Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort hash by dates

Status
Not open for further replies.

EfratS

MIS
Aug 4, 2004
15
CA
Hi,

How can I sort hash by date?

Thanks..
 
Assuming your hash uses dates for the keys, first write a function that compares two dates and returns -1 if the first is less than the second, or 1 if the first is greater than the second, or 0 if they are equal. Then do this:

Code:
my @sortedKeys = sort { compareDates ($a, $b); } keys %hash;

I would give you the code for the date comparison function, but I have no idea how you have formatted the dates (e.g. seconds from epoch, day of the year, MM/DD/YYYY, DD/MM/YYYY, YYYY-MM-DD, etc.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top