in reply to Sort Hash of Hashes by key value

It is fairly easy to do. You can use the values function to get back a list of hash elements. eg

 my @items = values %srvlist

That will give you a list in a random(ish) order. To sort the list, you can pass the sort function a closure that tell it how to sort. eg

 my @sorted_list = sort { $a->{'pctused'} <=> $b->{'pctused'} values %srvlist

$a and $b are temporary variables used only within the sort closure, <=> is the spaceship operator which numerically compares numbers. You would use cmp if you where comparing strings.

Edit: Correct an error pointed out by johngg. Thanks

Replies are listed 'Best First'.
Re^2: Sort Hash of Hashes by key value
by johngg (Canon) on Mar 14, 2011 at 19:39 UTC

    I'm puzzled by your recommendation of an "elements" function as that's a new one on me. Did you mean values, perchance?

    Cheers,

    JohnGG

      Yes I did, thanks.

      I think I was getting confused with another language.