Here's the scenario:
I receive text files on a regular basis. One file for each country named by XX.txt where 'XX' is the two letter country code. The complete list of the countries I have files for changes regularly. I need an <option> list that corresponds to the available countries.
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",
);
ect...
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.
I learn more and more about less and less until eventually I know everything about nothing.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.