in reply to sorting multidimensional arrays

Here's an optimization of my previous answer.

use strict; use warnings; my @unsorted_array = ([8,9,10], [6,5,4], [7,8,9]); my @order_lookup; { my $row = $unsorted_array[1]; @order_lookup = sort { $row->[$a] <=> $row->[$b] } 0..$#$row; } my @sorted_array; { my $num_rows = @unsorted_array; my $num_cols = @{$unsorted_array[0]}; foreach my $row (@unsorted_array) { push(@sorted_array, [ map { $row->[$_] } @order_lookup ]); } } require Data::Dumper; print(Data::Dumper::Dumper(\@sorted_array));