Use a Schwartzian transform - like this: (update: but see salva's comment below for a better approach)

@sorted = map {$_->[0]} map { $i=0; sort {$b->[1]<=>$a->[1]} map {[$i++,$_]} splice (@s +im,0,9) } 0..8; print "\@index_ordered =(\n"; for(0..8) { print " " x 4, join(', ', splice (@sorted,0,9) ),"\n"; } print ");\n";

Output:

@index_ordered =( 0, 1, 3, 2, 4, 5, 7, 8, 6 1, 0, 3, 8, 2, 4, 7, 6, 5 2, 3, 8, 0, 1, 4, 7, 5, 6 3, 0, 1, 2, 8, 7, 6, 4, 5 4, 8, 7, 0, 1, 2, 6, 3, 5 5, 0, 7, 1, 2, 3, 6, 8, 4 6, 7, 8, 3, 4, 1, 2, 0, 5 7, 6, 8, 3, 4, 0, 1, 5, 2 8, 7, 6, 3, 4, 1, 2, 0, 5 );

For equal elements in each row of @sim the order of their indices is undetermined. Note that this is destructive to @sim - it will be empty after the sort.

While the above code DWYM, you would have been better off having an array of arrays in the first place.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Sorting Index of An Array by shmem
in thread Sorting Index of An Array by neversaint

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.