in reply to Maintainability of hash-sorting code

I would write your first loop differently. There's no need to sort the keys of the hash, as you are only modifying the values here. Secondly, since you are modifying just the values, I'd use values instead of keys. reverse in combination with sort is not really necessary, just reverse the condition in the block. Finally, don't splice if you can use a slice - specially not if you do it with a large detour the way you did. This is my loop:
foreach my $orders (values %data) { my @orders = sort {$b <=> $a} @$orders; $orders = [@orders [0 .. ($#orders < 5 ? $#orders : 4)]]; }

Abigail