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


In reply to Re^6: Sorting an array of hashes with an exeption by martin_87
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.