in reply to Re: hash sorting/alphabetization issue : country postal codes
in thread hash sorting/alphabetization issue : country postal codes

Thank you. I understand the problem in my thinking now. I see that I needed to sort previous to the foreach loop rather than in it. I know there are always multiple ways to do things, but this one makes sense to me.

I learn more and more about less and less until eventually I know everything about nothing.
  • Comment on Re^2: hash sorting/alphabetization issue : country postal codes

Replies are listed 'Best First'.
Re^3: hash sorting/alphabetization issue : country postal codes
by ikegami (Patriarch) on Jul 04, 2007 at 03:32 UTC

    I see that I needed to sort previous to the foreach loop rather than in it.

    No, that's not the problem you were having. And there's no problem with putting the sort inside the foreach statement.

    my @codes = map { substr($_, 0, rindex($_, '.')) } @intl_files; foreach my $code ( sort { $country_names{$a} cmp $country_names{$b} } ) { print "<option value=\"$code\">$country_names{$code}</option>\n"; }