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

Sure. 2.1 < 2.5, therefore 5 gets first. Try setting Distance of 5 to 3.1.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re^3: Sorting an array of hashes with an exeption

Replies are listed 'Best First'.
Re^4: Sorting an array of hashes with an exeption
by martin_87 (Initiate) on May 10, 2013 at 15:31 UTC

    I don't know how this solution can be at any help.

    Instead of changing distance I might aswell just change the RouteDistance to a bigger number and hope for the best..

      I probably still do not understand how you want the results sorted. Can you give a more detailed description?
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Sorry if I made the last post seem angry but I'm tired and a bit frustrated atm. Not my intention at all to sound mad at you directly.

        So the problem that I have is the following. I'm receiving an hash from an XMLpost. This hash contains alot of information but the only parts that I need is ID, Name, Distance and RouteDistance. I have not mentined Name before but it does not make any differance in this sorting problem that I got. This post needs to be sorted before presented. This sort should be easy if it wasn't for the cases where RouteDistance is zero. RouteDistance is the priority element that this sort should be done on but in those cases where RouteDistance is zero, the fallback is to match the Distance for the RouteDistance instead (but only the one which is zero). Then the sorting continues on RouteDistance until a new RouteDistance with zero arraives and in that case, same thing, sort this in on distance instead.

        The XMLpost contains of a maximum of 20 hashes so there is room fore some bad performance sorting aswell. Ofcourse a fast and clean solution would be the best but as this point I'm open for any soltion that would solve this problem.

        As I wrote in the "uptate 1" post in the original post I can accept an solution where the RouteDistance value is modified by for example + 0.01 / - 0.01 (depending how the loop is iterating over the array) with the nearest RouteDistance.

        I do find my example tables informative where I first wrote the original data and then what I expect after the sort is done.

        If you need more information you let me know, I find this a bit hard to describe, escpecially since I'm not that good at English