in reply to Re: Sorting an array of hashes with an exeption
in thread Sorting an array of hashes with an exception

Hi, thanks for the fast reply. The code which you provided gave me this result:

ID = 5, Distance = 2.1, RouteDistance = 0
ID = 1, Distance = 1.7, RouteDistance = 2.5
ID = 2, Distance = 1.5, RouteDistance = 2.8
ID = 3, Distance = 2.3, RouteDistance = 4.3

It looks like it sorts by RouteDistance only here.

The answer which BrowserUK provided works like a charm but I would like to know if you could provide an example where i add an argument as you where hinting about?
  • Comment on Re^2: Sorting an array of hashes with an exeption

Replies are listed 'Best First'.
Re^3: Sorting an array of hashes with an exeption
by choroba (Cardinal) on May 09, 2013 at 13:07 UTC
    It looks like it sorts by RouteDistance only here.
    Not really. Try setting Distance to 3.1 at ID 5.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      You're right, It doesn't only sort by RouteDistance. I didn't look long enough at the code, just the result. My bad.

      The result when changing ID: 5 with a distance of: 3.1 I get the following result:

      ID: 1 Distance: 1.7 RouteDistance: 2.5
      ID: 5 Distance: 3.1 RouteDistance: 0
      ID: 2 Distance: 1.5 RouteDistance: 2.8
      ID: 3 Distance: 2.3 RouteDistance: 4.3

      This is my excpected result but then again, it will not work in all cases :/

        Ouch, I had a precedence error in the code. Fixed now with the parentheses.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ