Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Custom Sort An AoA

by Corion (Pope)
on Apr 01, 2014 at 16:10 UTC ( #1080597=note: print w/ replies, xml ) Need Help??


in reply to Custom Sort An AoA

The general trick is to append your additional sort criteria to the sort block.

@list= sort { @$a <=> @$b || ... secondary criterion ... || ... tertiary criterion ... } @list;

So all that remains is to find the appropriate expression to find and compare the last elements of each array:

$a->[-1] cmp $b->[-1] # untested

Taken together, your sort expression would be

@list= sort { @$a <=> @$b || $a->[-1] cmp $b->[-1] } @list;


Comment on Re: Custom Sort An AoA
Select or Download Code
Re^2: Custom Sort An AoA
by Limbic~Region (Chancellor) on Apr 01, 2014 at 17:09 UTC
    Corion,
    I must not have done a good job of explaining.

    Start at the last element and if they are equivalent then check the next to the last and if they are equivalent check the next to the next to the last....

    Your solution fails to produce the correct output because you are only comparing the last element.

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2014-09-17 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (97 votes), past polls