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 }
In reply to Re: How to sort a non-unique value within unique values
by duff
in thread How to sort a non-unique value within unique values
by hmbscully
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |