http://qs321.pair.com?node_id=1080638


in reply to Custom Sort An AoA

A solution using List::MoreUtils.

Isn't the most efficient since it doesn't shortcut the comparing of array elements. Also duplicates the use of localized $a and $b, but overall I think this is very readable.

use List::MoreUtils qw(lastval pairwise); my @array = ( ['blah', 'asdf', 'foo', 'bar'], ['two'], ['zzz', 'def', 'ghi'], ['one'], ['mmm', 'def', 'ghi'], ['qqq', 'xyz', 'aaa'], ); @array = sort {@$a <=> @$b or lastval {$_} pairwise {$a cmp $b} @$a, @ +$b} @array; use Data::Dump; dd \@array;
- Miller