Have you considered that this problem might not have a solution for some inputs? At least not with the rules that you have given us (as I understood them).

Consider these data records, already pre-sorted according to route distance.

ID = 5, Distance = 1,6, 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

IDs 1 2 and 3 are well sorted and need to stay in this order. Then, of course, the first line needs to be moved to be inserted somewhere else according to the Distance. But where are you going to insert it? Because IDs 1, 2 and 3 are not ordered for distance, it is not possible to insert ID 5 anywhere. For example, if you put it after ID 2, OK, it will be OK compared to ID 2 and 3, but it will be after ID 1, although its distance is smaller. Any other solution will fail likewise.


In reply to Re: Sorting an array of hashes with an exeption by Laurent_R
in thread Sorting an array of hashes with an exception by martin_87

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.