Not quite sure about the type of data structure that you intend. The code below would sort on 2nd column of matrix with 3 columns.
#!/usr/bin/perl -w use strict; use Data::Dumper; my @AoA = ([1,2,3], [1,1,3], [1,5,2], [0,-1,3] ); print Dumper(\@AoA); @AoA = sort{@$a[1] <=> @$b[1] }@AoA; print Dumper(\@AoA);
Part of my "non-understanding" is: I have a list of indices from an array that was numerically sorted. The natural thing would be to have that array in the sorted order! I don't understand why I should mess with: thing 15 should be in the place thing 2 is in now, etc. If the array is sorted, then I don't need the indices. The array is just going to be sorted further.

Can you write a simple Perl variable declaration with the type of structure that you want to sort? Something like this would be a "3D" thing.

my @AoAoA = ( [ [1,2,3] ,[1,1,3],[1,5,2] ], [ [0,-1,3],[1,5,2],[3,2,1] ], [ [0,-1,3],[1,-1,3],[5,4,2] ], );
In Perl something like that or even what I showed above for a matrix is rare. The closest Perl equivalent to a 'C' 2D array is an array of hash. The reason is that this avoids all this index 1 really means NAME sort of stuff.

In reply to Re: Sorting multidimensional arrays using a list of indices by Marshall
in thread Sorting multidimensional arrays using a list of indices by eas2domine

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.