Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: need to sort array of hash

by kcott (Archbishop)
on Dec 22, 2018 at 11:52 UTC ( [id://1227608]=note: print w/replies, xml ) Need Help??


in reply to need to sort array of hash

I agree with ++dsheroh's assessment. Simplifying the data structure results in a simpler sort (i.e. easier to read and maintain).

Here's a quick-and-dirty example to show the simplified sort logic:

$ perl -E ' my %x = (A=>{h=>2}, B=>{h=>1}, C=>{h=>3}); say for sort { $x{$b}{h} <=> $x{$a}{h} } keys %x; ' C A B

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found