Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Custom Sort An AoA

by wind (Priest)
on Apr 01, 2014 at 20:28 UTC ( #1080638=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1080638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-12-05 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?