in reply to Sort function issue
To break this down, follow it backwards. Starting at keys -- for each key in the hash, the last map builds pairs of values. The first number of the pair is the end value you want. The second number of the pair is what you want to sort by.sub sorted_by_dept(\%) { my $href = shift; my @sorted = map {$_->[0] } sort {$a->[1] <=> $b->[1] } map { [$_, $href->{$_}->{dept}] } keys %$href; return @sorted; }
|
|---|