Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: how to sort HoH according to value

by sgifford (Prior)
on Jun 19, 2008 at 02:28 UTC ( #692835=note: print w/replies, xml ) Need Help??

in reply to how to sort HoH according to value


The key thing to realize here is that a hash doesn't have any notion of order. The most straightforward solution is to copy the information you want from the hash into a list, which is ordered, then sort the list. For example:

# Convert HoH into a list of arrayrefs: [value, key1, key2, ...] my @list; while (my($k1,$v1) = each(%HoH)) { while (my($k2,$v2) = each(%$v1)) { push @list, [$v2, $k1, $k2]; } } # Sort the list by its first element @list = sort { $a->[0] <=> $b->[0] } @list; # Now print the list foreach my $elt (@list) { print "@$elt\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://692835]
[Corion]: thezip: Yeah - we have "CAP", but that means "Change Ablauf Plan" (Change Sequence Plan). Likely there is a true ITIL name for this too.
[Corion]: While I'm not really a fan of ITIL, it certainly is better than nothing and it at least provides a common vocabulary, so if you have ITIL somewhere at your disposal, it might be worth a look
[Corion]: Hmm - that should be somewhere in the "Release Deployment Plan", but I don't find a good English link (nor a good German one ;) )
[thezip]: My project manager is asking "Why do we need this?" Ahem...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-02-23 17:57 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (350 votes). Check out past polls.