Tie::Hash package that allows you to look up ISO 3166 Country names by alpha-2 code, "Short Country Name" and "alpha-2 Short Country Name". Returns "alpha 2 Short Name". Exists & defined work as expected.
Added updated version Locale::Country::TieHash that grabs the ISO data from the now standard Local::Country
package WWE::Country::ISO;
use 5.002;
use strict;
use warnings;
use Tie::Hash;
use Carp;
our @ISA = qw(Tie::StdHash);
my %CountryHash = (
"af" => "AF Afghanistan",
"afghanistan" => "AF Afghanistan",
"al" => "AL Albania",
"albania" => "AL Albania",
"dz" => "DZ Algeria",
"algeria" => "DZ Algeria",
"as" => "AS American Samoa",
"american samoa" => "AS American Samoa",
"ad" => "AD Andorra",
"andorra" => "AD Andorra",
"ao" => "AO Angola",
"angola" => "AO Angola",
"ai" => "AI Anguilla",
"anguilla" => "AI Anguilla",
"aq" => "AQ Antarctica",
"antarctica" => "AQ Antarctica",
"ag" => "AG Antigua and Barbuda",
"antigua and barbuda" => "AG Antigua and Barbuda",
"ar" => "AR Argentina",
"argentina" => "AR Argentina",
"am" => "AM Armenia",
"armenia" => "AM Armenia",
"aw" => "AW Aruba",
"aruba" => "AW Aruba",
"au" => "AU Australia",
"australia" => "AU Australia",
"at" => "AT Austria",
"austria" => "AT Austria",
"az" => "AZ Azerbaijan",
"azerbaijan" => "AZ Azerbaijan",
"bs" => "BS Bahamas",
"bahamas" => "BS Bahamas",
"bh" => "BH Bahrain",
"bahrain" => "BH Bahrain",
"bd" => "BD Bangladesh",
"bangladesh" => "BD Bangladesh",
"bb" => "BB Barbados",
"barbados" => "BB Barbados",
"by" => "BY Belarus",
"belarus" => "BY Belarus",
"be" => "BE Belgium",
"belgium" => "BE Belgium",
"bz" => "BZ Belize",
"belize" => "BZ Belize",
"bj" => "BJ Benin",
"benin" => "BJ Benin",
"bm" => "BM Bermuda",
"bermuda" => "BM Bermuda",
"bt" => "BT Bhutan",
"bhutan" => "BT Bhutan",
"bo" => "BO Bolivia",
"bolivia" => "BO Bolivia",
"ba" => "BA Bosnia and Herzegovina",
"bosnia and herzegovina" => "BA Bosnia and Herzegovina",
"bw" => "BW Botswana",
"botswana" => "BW Botswana",
"bv" => "BV Bouvet Island",
"bouvet island" => "BV Bouvet Island",
"br" => "BR Brazil",
"brazil" => "BR Brazil",
"io" => "IO British Indian Ocean Territory",
"british indian ocean territory" => "IO British Indian Ocean T
+erritory",
"bn" => "BN Brunei Darussalam",
"brunei darussalam" => "BN Brunei Darussalam",
"bg" => "BG Bulgaria",
"bulgaria" => "BG Bulgaria",
"bf" => "BF Burkina Faso",
"burkina faso" => "BF Burkina Faso",
"bi" => "BI Burundi",
"burundi" => "BI Burundi",
"kh" => "KH Cambodia",
"cambodia" => "KH Cambodia",
"cm" => "CM Cameroon",
"cameroon" => "CM Cameroon",
"ca" => "CA Canada",
"canada" => "CA Canada",
"cv" => "CV Cape Verde",
"cape verde" => "CV Cape Verde",
"ky" => "KY Cayman Islands",
"cayman islands" => "KY Cayman Islands",
"cf" => "CF Central African Republic",
"central african republic" => "CF Central African Republic",
"td" => "TD Chad",
"chad" => "TD Chad",
"cl" => "CL Chile",
"chile" => "CL Chile",
"cn" => "CN China",
"china" => "CN China",
"cx" => "CX Christmas Island",
"christmas island" => "CX Christmas Island",
"cc" => "CC Cocos (Keeling) Islands",
"cocos (keeling) islands" => "CC Cocos (Keeling) Islands",
"co" => "CO Colombia",
"colombia" => "CO Colombia",
"km" => "KM Comoros",
"comoros" => "KM Comoros",
"cg" => "CG Congo",
"congo" => "CG Congo",
"cd" => "CD Congo, the Democratic Republic of the",
"congo, the democratic republic of the" => "CD Congo, the Demo
+cratic Republic of the",
"ck" => "CK Cook Islands",
"cook islands" => "CK Cook Islands",
"cr" => "CR Costa Rica",
"costa rica" => "CR Costa Rica",
"ci" => "CI Cote D\'Ivoire",
"cote d\'ivoire" => "CI Cote D\'Ivoire",
"hr" => "HR Croatia",
"croatia" => "HR Croatia",
"cu" => "CU Cuba",
"cuba" => "CU Cuba",
"cy" => "CY Cyprus",
"cyprus" => "CY Cyprus",
"cz" => "CZ Czech Republic",
"czech republic" => "CZ Czech Republic",
"dk" => "DK Denmark",
"denmark" => "DK Denmark",
"dj" => "DJ Djibouti",
"djibouti" => "DJ Djibouti",
"dm" => "DM Dominica",
"dominica" => "DM Dominica",
"do" => "DO Dominican Republic",
"dominican republic" => "DO Dominican Republic",
"tp" => "TP East Timor",
"east timor" => "TP East Timor",
"ec" => "EC Ecuador",
"ecuador" => "EC Ecuador",
"eg" => "EG Egypt",
"egypt" => "EG Egypt",
"sv" => "SV El Salvador",
"el salvador" => "SV El Salvador",
"gq" => "GQ Equatorial Guinea",
"equatorial guinea" => "GQ Equatorial Guinea",
"er" => "ER Eritrea",
"eritrea" => "ER Eritrea",
"ee" => "EE Estonia",
"estonia" => "EE Estonia",
"et" => "ET Ethiopia",
"ethiopia" => "ET Ethiopia",
"fk" => "FK Falkland Islands (Malvinas)",
"falkland islands (malvinas)" => "FK Falkland Islands (Malvina
+s)",
"fo" => "FO Faroe Islands",
"faroe islands" => "FO Faroe Islands",
"fj" => "FJ Fiji",
"fiji" => "FJ Fiji",
"fi" => "FI Finland",
"finland" => "FI Finland",
"fr" => "FR France",
"france" => "FR France",
"gf" => "GF French Guiana",
"french guiana" => "GF French Guiana",
"pf" => "PF French Polynesia",
"french polynesia" => "PF French Polynesia",
"tf" => "TF French Southern Territories",
"french southern territories" => "TF French Southern Territori
+es",
"ga" => "GA Gabon",
"gabon" => "GA Gabon",
"gm" => "GM Gambia",
"gambia" => "GM Gambia",
"ge" => "GE Georgia",
"georgia" => "GE Georgia",
"de" => "DE Germany",
"germany" => "DE Germany",
"gh" => "GH Ghana",
"ghana" => "GH Ghana",
"gi" => "GI Gibraltar",
"gibraltar" => "GI Gibraltar",
"gr" => "GR Greece",
"greece" => "GR Greece",
"gl" => "GL Greenland",
"greenland" => "GL Greenland",
"gd" => "GD Grenada",
"grenada" => "GD Grenada",
"gp" => "GP Guadeloupe",
"guadeloupe" => "GP Guadeloupe",
"gu" => "GU Guam",
"guam" => "GU Guam",
"gt" => "GT Guatemala",
"guatemala" => "GT Guatemala",
"gn" => "GN Guinea",
"guinea" => "GN Guinea",
"gw" => "GW Guinea-Bissau",
"guinea-bissau" => "GW Guinea-Bissau",
"gy" => "GY Guyana",
"guyana" => "GY Guyana",
"ht" => "HT Haiti",
"haiti" => "HT Haiti",
"hm" => "HM Heard Island and Mcdonald Islands",
"heard island and mcdonald islands" => "HM Heard Island and Mc
+donald Islands",
"va" => "VA Holy See (Vatican City State)",
"holy see (vatican city state)" => "VA Holy See (Vatican City
+State)",
"hn" => "HN Honduras",
"honduras" => "HN Honduras",
"hk" => "HK Hong Kong",
"hong kong" => "HK Hong Kong",
"hu" => "HU Hungary",
"hungary" => "HU Hungary",
"is" => "IS Iceland",
"iceland" => "IS Iceland",
"in" => "IN India",
"india" => "IN India",
"id" => "ID Indonesia",
"indonesia" => "ID Indonesia",
"ir" => "IR Iran, Islamic Republic of",
"iran, islamic republic of" => "IR Iran, Islamic Republic of",
"iq" => "IQ Iraq",
"iraq" => "IQ Iraq",
"ie" => "IE Ireland",
"ireland" => "IE Ireland",
"il" => "IL Israel",
"israel" => "IL Israel",
"it" => "IT Italy",
"italy" => "IT Italy",
"jm" => "JM Jamaica",
"jamaica" => "JM Jamaica",
"jp" => "JP Japan",
"japan" => "JP Japan",
"jo" => "JO Jordan",
"jordan" => "JO Jordan",
"kz" => "KZ Kazakstan",
"kazakstan" => "KZ Kazakstan",
"ke" => "KE Kenya",
"kenya" => "KE Kenya",
"ki" => "KI Kiribati",
"kiribati" => "KI Kiribati",
"kp" => "KP Korea, Democratic People\'S Republic of",
"korea, democratic people\'s republic of" => "KP Korea, Democr
+atic People\'S Republic of",
"kr" => "KR Korea, Republic of",
"korea, republic of" => "KR Korea, Republic of",
"kw" => "KW Kuwait",
"kuwait" => "KW Kuwait",
"kg" => "KG Kyrgyzstan",
"kyrgyzstan" => "KG Kyrgyzstan",
"la" => "LA Lao People\'S Democratic Republic",
"lao people\'s democratic republic" => "LA Lao People\'S Democ
+ratic Republic",
"lv" => "LV Latvia",
"latvia" => "LV Latvia",
"lb" => "LB Lebanon",
"lebanon" => "LB Lebanon",
"ls" => "LS Lesotho",
"lesotho" => "LS Lesotho",
"lr" => "LR Liberia",
"liberia" => "LR Liberia",
"ly" => "LY Libyan Arab Jamahiriya",
"libyan arab jamahiriya" => "LY Libyan Arab Jamahiriya",
"li" => "LI Liechtenstein",
"liechtenstein" => "LI Liechtenstein",
"lt" => "LT Lithuania",
"lithuania" => "LT Lithuania",
"lu" => "LU Luxembourg",
"luxembourg" => "LU Luxembourg",
"mo" => "MO Macau",
"macau" => "MO Macau",
"mk" => "MK Macedonia, the Former Yugoslav Republic of",
"macedonia, the former yugoslav republic of" => "MK Macedonia,
+ the Former Yugoslav Republic of",
"mg" => "MG Madagascar",
"madagascar" => "MG Madagascar",
"mw" => "MW Malawi",
"malawi" => "MW Malawi",
"my" => "MY Malaysia",
"malaysia" => "MY Malaysia",
"mv" => "MV Maldives",
"maldives" => "MV Maldives",
"ml" => "ML Mali",
"mali" => "ML Mali",
"mt" => "MT Malta",
"malta" => "MT Malta",
"mh" => "MH Marshall Islands",
"marshall islands" => "MH Marshall Islands",
"mq" => "MQ Martinique",
"martinique" => "MQ Martinique",
"mr" => "MR Mauritania",
"mauritania" => "MR Mauritania",
"mu" => "MU Mauritius",
"mauritius" => "MU Mauritius",
"yt" => "YT Mayotte",
"mayotte" => "YT Mayotte",
"mx" => "MX Mexico",
"mexico" => "MX Mexico",
"fm" => "FM Micronesia, Federated States of",
"micronesia, federated states of" => "FM Micronesia, Federated
+ States of",
"md" => "MD Moldova, Republic of",
"moldova, republic of" => "MD Moldova, Republic of",
"mc" => "MC Monaco",
"monaco" => "MC Monaco",
"mn" => "MN Mongolia",
"mongolia" => "MN Mongolia",
"ms" => "MS Montserrat",
"montserrat" => "MS Montserrat",
"ma" => "MA Morocco",
"morocco" => "MA Morocco",
"mz" => "MZ Mozambique",
"mozambique" => "MZ Mozambique",
"mm" => "MM Myanmar",
"myanmar" => "MM Myanmar",
"na" => "NA Namibia",
"namibia" => "NA Namibia",
"nr" => "NR Nauru",
"nauru" => "NR Nauru",
"np" => "NP Nepal",
"nepal" => "NP Nepal",
"nl" => "NL Netherlands",
"netherlands" => "NL Netherlands",
"an" => "AN Netherlands Antilles",
"netherlands antilles" => "AN Netherlands Antilles",
"nc" => "NC New Caledonia",
"new caledonia" => "NC New Caledonia",
"nz" => "NZ New Zealand",
"new zealand" => "NZ New Zealand",
"ni" => "NI Nicaragua",
"nicaragua" => "NI Nicaragua",
"ne" => "NE Niger",
"niger" => "NE Niger",
"ng" => "NG Nigeria",
"nigeria" => "NG Nigeria",
"nu" => "NU Niue",
"niue" => "NU Niue",
"nf" => "NF Norfolk Island",
"norfolk island" => "NF Norfolk Island",
"mp" => "MP Northern Mariana Islands",
"northern mariana islands" => "MP Northern Mariana Islands",
"no" => "NO Norway",
"norway" => "NO Norway",
"om" => "OM Oman",
"oman" => "OM Oman",
"pk" => "PK Pakistan",
"pakistan" => "PK Pakistan",
"pw" => "PW Palau",
"palau" => "PW Palau",
"ps" => "PS Palestinian Territory, Occupied",
"palestinian territory, occupied" => "PS Palestinian Territory
+, Occupied",
"pa" => "PA Panama",
"panama" => "PA Panama",
"pg" => "PG Papua New Guinea",
"papua new guinea" => "PG Papua New Guinea",
"py" => "PY Paraguay",
"paraguay" => "PY Paraguay",
"pe" => "PE Peru",
"peru" => "PE Peru",
"ph" => "PH Philippines",
"philippines" => "PH Philippines",
"pn" => "PN Pitcairn",
"pitcairn" => "PN Pitcairn",
"pl" => "PL Poland",
"poland" => "PL Poland",
"pt" => "PT Portugal",
"portugal" => "PT Portugal",
"pr" => "PR Puerto Rico",
"puerto rico" => "PR Puerto Rico",
"qa" => "QA Qatar",
"qatar" => "QA Qatar",
"re" => "RE Reunion",
"reunion" => "RE Reunion",
"ro" => "RO Romania",
"romania" => "RO Romania",
"ru" => "RU Russian Federation",
"russian federation" => "RU Russian Federation",
"rw" => "RW Rwanda",
"rwanda" => "RW Rwanda",
"sh" => "SH Saint Helena",
"saint helena" => "SH Saint Helena",
"kn" => "KN Saint Kitts and Nevis",
"saint kitts and nevis" => "KN Saint Kitts and Nevis",
"lc" => "LC Saint Lucia",
"saint lucia" => "LC Saint Lucia",
"pm" => "PM Saint Pierre and Miquelon",
"saint pierre and miquelon" => "PM Saint Pierre and Miquelon",
"vc" => "VC Saint Vincent and the Grenadines",
"saint vincent and the grenadines" => "VC Saint Vincent and th
+e Grenadines",
"ws" => "WS Samoa",
"samoa" => "WS Samoa",
"sm" => "SM San Marino",
"san marino" => "SM San Marino",
"st" => "ST Sao Tome and Principe",
"sao tome and principe" => "ST Sao Tome and Principe",
"sa" => "SA Saudi Arabia",
"saudi arabia" => "SA Saudi Arabia",
"sn" => "SN Senegal",
"senegal" => "SN Senegal",
"sc" => "SC Seychelles",
"seychelles" => "SC Seychelles",
"sl" => "SL Sierra Leone",
"sierra leone" => "SL Sierra Leone",
"sg" => "SG Singapore",
"singapore" => "SG Singapore",
"sk" => "SK Slovakia",
"slovakia" => "SK Slovakia",
"si" => "SI Slovenia",
"slovenia" => "SI Slovenia",
"sb" => "SB Solomon Islands",
"solomon islands" => "SB Solomon Islands",
"so" => "SO Somalia",
"somalia" => "SO Somalia",
"za" => "ZA South Africa",
"south africa" => "ZA South Africa",
"gs" => "GS South Georgia and the South Sandwich Islands",
"south georgia and the south sandwich islands" => "GS South Ge
+orgia and the South Sandwich Islands",
"es" => "ES Spain",
"spain" => "ES Spain",
"lk" => "LK Sri Lanka",
"sri lanka" => "LK Sri Lanka",
"sd" => "SD Sudan",
"sudan" => "SD Sudan",
"sr" => "SR Suriname",
"suriname" => "SR Suriname",
"sj" => "SJ Svalbard and Jan Mayen",
"svalbard and jan mayen" => "SJ Svalbard and Jan Mayen",
"sz" => "SZ Swaziland",
"swaziland" => "SZ Swaziland",
"se" => "SE Sweden",
"sweden" => "SE Sweden",
"ch" => "CH Switzerland",
"switzerland" => "CH Switzerland",
"sy" => "SY Syrian Arab Republic",
"syrian arab republic" => "SY Syrian Arab Republic",
"tw" => "TW Taiwan, Province of China",
"taiwan, province of china" => "TW Taiwan, Province of China",
"tj" => "TJ Tajikistan",
"tajikistan" => "TJ Tajikistan",
"tz" => "TZ Tanzania, United Republic of",
"tanzania, united republic of" => "TZ Tanzania, United Republi
+c of",
"th" => "TH Thailand",
"thailand" => "TH Thailand",
"tg" => "TG Togo",
"togo" => "TG Togo",
"tk" => "TK Tokelau",
"tokelau" => "TK Tokelau",
"to" => "TO Tonga",
"tonga" => "TO Tonga",
"tt" => "TT Trinidad and Tobago",
"trinidad and tobago" => "TT Trinidad and Tobago",
"tn" => "TN Tunisia",
"tunisia" => "TN Tunisia",
"tr" => "TR Turkey",
"turkey" => "TR Turkey",
"tm" => "TM Turkmenistan",
"turkmenistan" => "TM Turkmenistan",
"tc" => "TC Turks and Caicos Islands",
"turks and caicos islands" => "TC Turks and Caicos Islands",
"tv" => "TV Tuvalu",
"tuvalu" => "TV Tuvalu",
"ug" => "UG Uganda",
"uganda" => "UG Uganda",
"ua" => "UA Ukraine",
"ukraine" => "UA Ukraine",
"ae" => "AE United Arab Emirates",
"united arab emirates" => "AE United Arab Emirates",
"gb" => "GB United Kingdom",
"united kingdom" => "GB United Kingdom",
"us" => "US United States",
"united states" => "US United States",
"um" => "UM United States Minor Outlying Islands",
"united states minor outlying islands" => "UM United States Mi
+nor Outlying Islands",
"uy" => "UY Uruguay",
"uruguay" => "UY Uruguay",
"uz" => "UZ Uzbekistan",
"uzbekistan" => "UZ Uzbekistan",
"vu" => "VU Vanuatu",
"vanuatu" => "VU Vanuatu",
"ve" => "VE Venezuela",
"venezuela" => "VE Venezuela",
"vn" => "VN Viet Nam",
"viet nam" => "VN Viet Nam",
"vg" => "VG Virgin Islands, British",
"virgin islands, british" => "VG Virgin Islands, British",
"vi" => "VI Virgin Islands, U.S.",
"virgin islands, u.s." => "VI Virgin Islands, U.S.",
"wf" => "WF Wallis and Futuna",
"wallis and futuna" => "WF Wallis and Futuna",
"eh" => "EH Western Sahara",
"western sahara" => "EH Western Sahara",
"ye" => "YE Yemen",
"yemen" => "YE Yemen",
"yu" => "YU Yugoslavia",
"yugoslavia" => "YU Yugoslavia",
"zm" => "ZM Zambia",
"zambia" => "ZM Zambia",
"zw" => "ZW Zimbabwe",
"zimbabwe" => "ZW Zimbabwe",
);
our $VERSION = '0.01';
sub TIEHASH {
my $class = shift;
my $self = {};
$self->{DAT} = \%CountryHash;
my @k = grep { /^\w\w$/ } sort { $self->{DAT}{$a} cmp $self->
+{DAT}{$b} } keys %{$self->{DAT}};
$self->{keys} = \@k;
$self->{key_index} = 0;
return bless $self, $class;
}
sub STORE {
my ($self, $key, $value) = @_;
croak __PACKAGE__,":Cannot set value for $key! READ-ONLY";
}
sub DELETE {
my ($self, $key, $value) = @_;
croak __PACKAGE__,":Cannot delete value for $key! READ-ONLY";
}
sub FETCH {
my ($self, $key) = @_;
$key=~/^(\w\w)\s/;
my $ikey = lc($1 || $key);
return $self->{DAT}{lc $ikey};
}
sub EXISTS {
my ($self, $key) = @_;
$key=~/^(\w\w)\s/;
my $ikey = lc($1 || $key);
return exists $self->{DAT}{lc $ikey};
}
sub DEFINED {
my ($self, $key) = @_;
$key=~/^(\w\w)\s/;
my $ikey = lc($1 || $key);
return defined $self->{DAT}{lc $ikey};
}
sub FIRSTKEY {
my $self = shift;
$self->{key_index} = 0;
return $self->{DAT}{ $self->{keys}->[$self->{key_index}++] };
}
sub NEXTKEY {
my $self = shift;
return undef unless defined($self->{keys}[ $self->{key_index}]);
return $self->{DAT}{$self->{keys}[ $self->{key_index}++] };
}
sub CLEAR {
croak __PACKAGE__,":Cannot clear Country Hash! READ-ONLY";
}
1;
__END__
# Below is stub documentation for your module. You better edit it!
=head1 NAME
WWE::Country::ISO - Perl extension for Validating Country codes via ti
+ed-hash
=head1 SYNOPSIS
use WWE::Country::ISO;
tie %Countries, 'WWE::Country::ISO';
=head1 DESCRIPTION
tie %Countries, 'WWE::Country::ISO';
my $country = "United StAtes";
die "Invalid $country" unless exists($Countries{$country});
print $Countries{'Us'},"\n"; # Prints US United
+ States
print $Countries{'Us UnitEd StateS'},"\n"; # Prints US United S
+tates
print $Countries{'United States'},"\n"; # Prints US United
+States
my @states = keys %Countries; # Returns ISO 3166
+ names sorted.
Let's you look up countries by ISO 3166 Alpha-2abbreviations, Country
+name
and ISO 3166 country name. (Case-insensitive)
Exists and defined work as you would expect.
Use at your own risk :)
=head2 EXPORT
None by default.
=head1 AUTHOR
Pumphret, Lee, E<lt>perl@leeland.net<gt>
=head1 COPYRIGHT
Copyright (C) 2002 Lee Pumphret
All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
+
under the same terms as Perl itself.
=head1 SEE ALSO
None
L<perl>.
=cut
-Lee
"To be civilized is to deny one's nature."