hmbscully has asked for the wisdom of the Perl Monks concerning the following question:
I have a hash of all the country codes and the country names
A bit of that hash:
%country_names = ( "AF" => "Afghanistan", "AX" => "Aland Islands", "AL" => "Albania", "DZ" => "Algeria", "AS" => "American Samoa", "AD" => "Andorra", "AO" => "Angola", "AI" => "Anguilla", "AQ" => "Antarctica", "AG" => "Antigua And Barbuda", "AR" => "Argentina", "AM" => "Armenia", "AW" => "Aruba", "AU" => "Australia", "AT" => "Austria", "AZ" => "Azerbaijan", "BS" => "Bahamas", "BH" => "Bahrain", "BD" => "Bangladesh", "BB" => "Barbados", );
What I want to do is this:
opendir(ODIR, "$sr_data/f") || die ("Unable to open directory $sr_data +/f"); @intl_files = grep !/^\./, readdir ODIR; #this line gets rid o +f . and .. closedir ODIR; open(FILE,">$includes_codes_dir/sc_intl_dd.txt"); foreach $file (sort @intl_files) { $file =~ s/\.\w+$//; #remove the extension print FILE "<option value=\"$file\">$country_names{$file +}</option>\n"; } close(FILE);
Which does build me an option list, but the problem is that the option items are in alphabetical order based on the country codes, not the country names. I know it has to do with ordering somewhere along the line, but I'm just having trouble seeing the logic.
Make any sense?
Thanks.
|
|---|