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 %srvlistThat 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 | |
by chrestomanci (Priest) on Mar 14, 2011 at 19:55 UTC |