If you need only the three top elements, then sorting the array of arrays is overkill and will be inefficient if the master array is large. Not good if speed is really important.

I would go for a selection algorithm could be done in two different ways: (1) the simpler (but slower) is to walk through the array once and memorize the array ref of the top element; then walk again through and find the next to top element, and a third time; (2) slightly more complicated is to walk through the array only once and to maintain as you go an auxiliary array of the three top elements; maintaining this auxiliary array is somewhat complicated, but nothing insurmountable.


In reply to Re: sorting array of arrays reference by Laurent_R
in thread sorting array of arrays reference by kimlid2810

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.