Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Hash sorting with dates and 12 hour time format.

by gwadej (Chaplain)
on Sep 15, 2009 at 21:09 UTC ( #795477=note: print w/ replies, xml ) Need Help??


in reply to Hash sorting with dates and 12 hour time format.

When working on a multi-key sort, it's important to text the items in the right order. In this case, you need to do the comparisons in the following order:

  1. month (9)
  2. day (10)
  3. am/pm (PM)
  4. hour (12)
  5. minute (45)

In addition, you will need to deal with the fact that 12:01 AM should sort to less than 1:00 AM. Your months also won't sort nicely ('10' sorting to less than '9').

You could break this string into a series of sub-keys and compare them in order, or pack them up into a fixed-field string that sorts how you want.

Once you've figured out your key, you'll want to apply either the Schwartzian Transform or the Guttman Rosler Transform to the problem.

Update: Added links for the algorithms.

G. Wade


Comment on Re: Hash sorting with dates and 12 hour time format.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2015-07-04 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls