in reply to Complex hash sorting
You might as well make the hash values refer to an array of the data,
You can now sort the keys any way you like by# $hash{$_} = [ split '||', $hash{$_} ] for keys %hash; $hash{$_} = [ split /\|\|/, $hash{$_} ] for keys %hash;
Notice the difference in comparison operator between numeric and dictionary data.my @by_zip = sort {$hash($a}[-1] <=> $hash{$b}[-1] } keys %hash; my @by_age = sort {$hash($a}[0] <=> $hash{$b}[0] } keys %hash; my @by_surname = sort { substr($a, rindex($a,' ')) cmp substr($b, rindex($b,' ')) } keys %hash;
Update: japhy++ is correct. Repaired without obscuring the damage.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Complex hash sorting
by japhy (Canon) on Feb 01, 2004 at 03:34 UTC |