in reply to How to sort a non-unique value within unique values
I'm not even sure you need the %testcenters hash (at least not for sorting purposes) because it sounds like you want to sort the test centers by city and for that all you need is the %centercity hash that you've already got. From your code it looks like you've got a series of "parallel hashes" all keyed on the test center name which is your unique identifier. You don't need to change this structure to use something more complicated (like the other fine suggestions given so far) if you don't want to.
Assuming my pile of assumptions are correct, you want something like this:
my @test_centers_sorted_by_city_then_name = sort { $centercity{$a} cmp + $centercity{$b} || $a cmp $b } keys %centercity; for my $center (@test_centers_sorted_by_city_then_name) { print "$center<br>"; # output test center name print "$centercity{$center}<br>"; # output city where test center +is located # ... output other stuff too }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to sort a non-unique value within unique values
by hmbscully (Scribe) on Sep 14, 2006 at 14:54 UTC |