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

Re: sort hash by value (sort array)

by Anonymous Monk
on Mar 24, 2014 at 13:01 UTC ( #1079518=note: print w/replies, xml ) Need Help??


in reply to sort hash by value

sort an array instead :) step 1, select values you want to keep from hash.... stuff into an array, sort the array by any value

http://learn.perl.org/faq/perlfaq4.html#How-do-I-sort-an-array-by-anything-, http://perldoc.perl.org/perlfaq4.html#How-do-I-sort-an-array-by-%28anything%29%3f

Understanding the Schwartzian transform., Re: Sorting a HoH by values of the nested hashes,

Replies are listed 'Best First'.
Re^2: sort hash by value (sort array)
by glenn (Scribe) on Mar 24, 2014 at 13:18 UTC
    That would be easier except this is tied into a GUI and user values are going into array 0, old values are in array 1. I think you may have given me an answer anyhow though; flaten tag, type, and string into a 2d array then sort then use that output to order the hash output...
    #head of code my @array; foreach my $tag (keys %licensehash) { foreach my $type (keys %{$licensehash{$tag}}) { push(@array, [$tag,$type,$licensehash{$tag}{$type}[3]]); } } @array = sort {$a->[2] cmp $b->[2]} @array; #body of program (used more than once) foreach my $order (@array) { print "$licensehash{@$order[0]}{@$order[1]}[3]"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-12-10 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (38 votes). Check out past polls.

    Notices?