Hello! This is the output I am trying to achieve...
$VAR1 = { 'Tucson' => 'AZ', 'Boston' => 'MA', 'Jackson' => 'MS', 'Dixon' => 'NM', 'Denton' => 'TX', 'Cincinnati' => 'OH' }; 1: Boston, MA 2: Cincinnati, OH 3: Denton, TX 4: Dixon, NM 5: Jackson, MS 6: Tucson, AZ
I am having trouble getting the cities to sort alphabetically and am not sure how to incorporate the numbering on the alphabetical sort. The Dumper output is just fine.
This is what I have so far...
#!/usr/bin/env perl use strict; use warnings; use autodie; use Data::Dumper; my %cities = ( Tucson => 'AZ', Boston => 'MA', Jackson => 'MS', Dixon => 'NM', Denton => 'TX', Cincinnati => 'OH', ); print Dumper(\%cities); foreach my $place (sort { $cities{$a} cmp $cities{$b} } keys %cities) +{ my $state = $cities{$place} ; print "$place, $state \n"; }
Thank you
In reply to sorting hash alphabetically with numbering by reebee3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |