in reply to hash sorting/alphabetization issue : country postal codes
my %country_names = ( "AF" => "Afghanistan", "AX" => "Aland Islands", "AL" => "Albania", "DZ" => "Algeria", "AS" => "American Samoa", "AD" => "Andorra", ); my @intl_files = <DATA>; chomp @intl_files; # not needed when using opendir/readdir #map removes the ".txt" file suffix #sort compares country names, not codes my @sorted = sort { $country_names{ $a } cmp $country_names{ $b } } map { substr( $_, 0, rindex( $_, '.' ) ) } @intl_files; foreach my $file ( @sorted ) { print "<option value=\"$file\">$country_names{$file}</option>\n"; } __DATA__ AL.txt DZ.txt AS.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash sorting/alphabetization issue : country postal codes
by hmbscully (Scribe) on Jul 03, 2007 at 20:06 UTC | |
by ikegami (Patriarch) on Jul 04, 2007 at 03:32 UTC |