Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://795477]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-03-20 20:10 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (259 votes). Check out past polls.