in reply to Re: Sorting Hash / Array
in thread Sorting Hash / Array
I'd rather see that sort routine inlined in this case. As it stands, nasty subtle bugs can creep in with some sloppy maintenance. Say at some point someone has to add $VAR2 and perform similar sorting on it... and make the all too simple mistake of thinking they can add a line that reads:
Oops. And that's just one example.my @result2 = sort custom keys %$VAR2;
This is perfectly readable:
my @result = sort { $VAR1->{$a}{network} cmp $VAR1->{$b}{network} } keys %$VAR1;
If it was something you had to do repeatedly, it would be better to wrap the whole sort in a sub...
sub keys_sorted_by_network { my $h = shift; sort { $h->{$a}{network} cmp $h->{$b}{network} } keys %$h; } my @result = keys_sorted_by_network($VAR1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting Hash / Array
by cdarke (Prior) on May 16, 2012 at 19:21 UTC | |
by sauoq (Abbot) on May 16, 2012 at 20:27 UTC |