1Locale::Country(3pm)   Perl Programmers Reference Guide   Locale::Country(3pm)
2
3
4

NAME

6       Locale::Country - ISO codes for country identification (ISO 3166)
7

SYNOPSIS

9           use Locale::Country;
10
11           $country = code2country('jp');        # $country gets 'Japan'
12           $code    = country2code('Norway');    # $code gets 'no'
13
14           @codes   = all_country_codes();
15           @names   = all_country_names();
16
17           # semi-private routines
18           Locale::Country::alias_code('uk' => 'gb');
19           Locale::Country::rename_country('gb' => 'Great Britain');
20

DESCRIPTION

22       The "Locale::Country" module provides access to the ISO codes for iden‐
23       tifying countries, as defined in ISO 3166-1.  You can either access the
24       codes via the "conversion routines" (described below), or with the two
25       functions which return lists of all country codes or all country names.
26
27       There are three different code sets you can use for identifying coun‐
28       tries:
29
30       alpha-2
31           Two letter codes, such as 'tv' for Tuvalu.  This code set is iden‐
32           tified with the symbol "LOCALE_CODE_ALPHA_2".
33
34       alpha-3
35           Three letter codes, such as 'brb' for Barbados.  This code set is
36           identified with the symbol "LOCALE_CODE_ALPHA_3".
37
38       numeric
39           Numeric codes, such as 064 for Bhutan.  This code set is identified
40           with the symbol "LOCALE_CODE_NUMERIC".
41
42       All of the routines take an optional additional argument which speci‐
43       fies the code set to use.  If not specified, it defaults to the two-
44       letter codes.  This is partly for backwards compatibility (previous
45       versions of this module only supported the alpha-2 codes), and partly
46       because they are the most widely used codes.
47
48       The alpha-2 and alpha-3 codes are not case-dependent, so you can use
49       'BO', 'Bo', 'bO' or 'bo' for Bolivia.  When a code is returned by one
50       of the functions in this module, it will always be lower-case.
51
52       As of version 2.00, Locale::Country supports variant names for coun‐
53       tries. So, for example, the country code for "United States" is "us",
54       so country2code('United States') returns 'us'.  Now the following will
55       also return 'us':
56
57           country2code('United States of America')
58           country2code('USA')
59

CONVERSION ROUTINES

61       There are three conversion routines: "code2country()", "coun‐
62       try2code()", and "country_code2code()".
63
64       code2country( CODE, [ CODESET ] )
65           This function takes a country code and returns a string which con‐
66           tains the name of the country identified.  If the code is not a
67           valid country code, as defined by ISO 3166, then "undef" will be
68           returned:
69
70               $country = code2country('fi');
71
72       country2code( STRING, [ CODESET ] )
73           This function takes a country name and returns the corresponding
74           country code, if such exists.  If the argument could not be identi‐
75           fied as a country name, then "undef" will be returned:
76
77               $code = country2code('Norway', LOCALE_CODE_ALPHA_3);
78               # $code will now be 'nor'
79
80           The case of the country name is not important.  See the section
81           "KNOWN BUGS AND LIMITATIONS" below.
82
83       country_code2code( CODE, CODESET, CODESET )
84           This function takes a country code from one code set, and returns
85           the corresponding code from another code set.
86
87               $alpha2 = country_code2code('fin',
88                            LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2);
89               # $alpha2 will now be 'fi'
90
91           If the code passed is not a valid country code in the first code
92           set, or if there isn't a code for the corresponding country in the
93           second code set, then "undef" will be returned.
94

QUERY ROUTINES

96       There are two function which can be used to obtain a list of all codes,
97       or all country names:
98
99       "all_country_codes( [ CODESET ] )"
100           Returns a list of all two-letter country codes.  The codes are
101           guaranteed to be all lower-case, and not in any particular order.
102
103       "all_country_names( [ CODESET ] )"
104           Returns a list of all country names for which there is a corre‐
105           sponding country code in the specified code set.  The names are
106           capitalised, and not returned in any particular order.
107
108           Not all countries have alpha-3 and numeric codes - some just have
109           an alpha-2 code, so you'll get a different number of countries
110           depending on which code set you specify.
111

SEMI-PRIVATE ROUTINES

113       Locale::Country provides two semi-private routines for modifying the
114       internal data.  Given their status, they aren't exported by default,
115       and so need to be called by prefixing the function name with the pack‐
116       age name.
117
118       alias_code
119
120       Define a new code as an alias for an existing code:
121
122           Locale::Country::alias_code( ALIAS => CODE [, CODESET ] )
123
124       This feature was added as a mechanism for handling a "uk" code. The ISO
125       standard says that the two-letter code for "United Kingdom" is "gb",
126       whereas domain names are all .uk.
127
128       By default the module does not understand "uk", since it is implement‐
129       ing an ISO standard. If you would like 'uk' to work as the two-letter
130       code for United Kingdom, use the following:
131
132           Locale::Country::alias_code('uk' => 'gb');
133
134       With this code, both "uk" and "gb" are valid codes for United Kingdom,
135       with the reverse lookup returning "uk" rather than the usual "gb".
136
137       Note: this function was previously called _alias_code, but the leading
138       underscore has been dropped.  The old name will be supported for all
139       2.X releases for backwards compatibility.
140
141       rename_country
142
143       If the official country name just isn't good enough for you, you can
144       rename a country. For example, the official country name for code 'gb'
145       is 'United Kingdom'.  If you want to change that, you might call:
146
147           Locale::Country::rename_country('gb' => 'Great Britain');
148
149       This means that calling code2country('gb') will now return 'Great
150       Britain' instead of 'United Kingdom'.  The original country name is
151       retained as an alias, so for the above example, country2code('United
152       Kingdom') will still return 'gb'.
153

EXAMPLES

155       The following example illustrates use of the "code2country()" function.
156       The user is prompted for a country code, and then told the correspond‐
157       ing country name:
158
159           $⎪ = 1;   # turn off buffering
160
161           print "Enter country code: ";
162           chop($code = <STDIN>);
163           $country = code2country($code, LOCALE_CODE_ALPHA_2);
164           if (defined $country)
165           {
166               print "$code = $country\n";
167           }
168           else
169           {
170               print "'$code' is not a valid country code!\n";
171           }
172

DOMAIN NAMES

174       Most top-level domain names are based on these codes, but there are
175       certain codes which aren't.  If you are using this module to identify
176       country from hostname, your best bet is to preprocess the country code.
177
178       For example, edu, com, gov and friends would map to us; uk would map to
179       gb. Any others?
180

KNOWN BUGS AND LIMITATIONS

182       ·   When using "country2code()", the country name must currently appear
183           exactly as it does in the source of the module. The module now sup‐
184           ports a small number of variants.
185
186           Possible extensions to this are: an interface for getting at the
187           list of variant names, and regular expression matches.
188
189       ·   In the current implementation, all data is read in when the module
190           is loaded, and then held in memory.  A lazy implementation would be
191           more memory friendly.
192
193       ·   Support for country names in different languages.
194

SEE ALSO

196       Locale::Language
197           ISO two letter codes for identification of language (ISO 639).
198
199       Locale::Script
200           ISO codes for identification of scripts (ISO 15924).
201
202       Locale::Currency
203           ISO three letter codes for identification of currencies and funds
204           (ISO 4217).
205
206       Locale::SubCountry
207           ISO codes for country sub-divisions (states, counties, provinces,
208           etc), as defined in ISO 3166-2.  This module is not part of the
209           Locale-Codes distribution, but is available from CPAN in CPAN/mod‐
210           ules/by-module/Locale/
211
212       ISO 3166-1
213           The ISO standard which defines these codes.
214
215       http://www.iso.org/iso/en/prods-services/iso3166ma/index.html
216           Official home page for the ISO 3166 maintenance agency.
217
218       http://www.egt.ie/standards/iso3166/iso3166-1-en.html
219           Another useful, but not official, home page.
220
221       http://www.cia.gov/cia/publications/factbook/docs/app-d-1.html
222           An appendix in the CIA world fact book which lists country codes as
223           defined by ISO 3166, FIPS 10-4, and internet domain names.
224

AUTHOR

226       Neil Bowers <neil@bowers.com>
227
229       Copyright (C) 2002-2004, Neil Bowers.
230
231       Copyright (c) 1997-2001 Canon Research Centre Europe (CRE).
232
233       This module is free software; you can redistribute it and/or modify it
234       under the same terms as Perl itself.
235
236
237
238perl v5.8.8                       2001-09-21              Locale::Country(3pm)
Impressum