in reply to How to sort HASH?

iwanthome,
If you are going to be adding/removing/updating keys and values, but you want the hash to always be sorted when accessing it, you can use Tie::Hash::Sorted.
use Tie::Hash::Sorted; my $custom_sort = sub { my $hash = shift; [ sort { $hash->{$b}{pkts} <=> $hash->{$a}{pkts} || $hash->{$b}{size} <=> $hash->{$a}{size} } keys %$hash ]; }; tie my %flows, 'Tie::Hash::Sorted', 'Sort_Routine' => $custom_sort, 'Optimization' => 'none' ; for ( keys %flows ) { # Will always be sorted the way you want }
If you encounter any bugs, let me know and I will try to fix them.

Cheers - L~R