Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Sorting an array using multiple values?

by AR (Friar)
on Sep 08, 2011 at 17:04 UTC ( #924876=note: print w/replies, xml ) Need Help??


in reply to Sorting an array using multiple values?

Firstly, what you have written won't work because you use "distance" in your data structure and "Distance" in your comparison. That being said, here you go:

my @loop_sorted = sort { $b->{isPaidLink} <=> $a->{isPaidLink} || $a->{distance} <=> $b->{distance} } @test;

Replies are listed 'Best First'.
Re^2: Sorting an array using multiple values?
by ultranerds (Hermit) on Sep 08, 2011 at 17:55 UTC
    Hi,

    Sorry, the "Distance" vs "distance" was a typo (I had a local test I played with, to get the values right - before using it on the live site , which used ->{Distance} and not ->{distance})

    Your code worked a charm, thanks! I'll have to remember that for the future, as I'm sure I will need similar code at some point

    Thanks again

    Andy

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2023-06-04 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (22 votes). Check out past polls.

    Notices?