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.#!/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);
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.
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.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 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |