56
56
<li><a href="http://search.cpan.org">CPAN</a></li>
57
<li><a href="http://www.perl.org">Perl.org</a></li>
57
58
<li><a href="http://www.perl.com">Perl.com</a></li>
58
<li><a href="http://www.perl.org">Perl.org</a></li>
59
<li><a href="http://perlbuzz.com">Perl Buzz</a></li>
60
<li><a href="http://www.perlfoundation.org/perl5/index.cgi">Perl 5 Wiki</a></li>
61
<li><a href="http://jobs.perl.org">Perl Jobs</a></li>
59
62
<li><a href="http://www.pm.org">Perl Mongers</a></li>
60
63
<li><a href="http://www.perlmonks.org">Perl Monks</a></li>
61
64
<li><a href="http://planet.perl.org">Planet Perl</a></li>
66
69
<li>Site maintained by<br><a href="http://perl.jonallen.info">Jon Allen</a>
67
70
(<a href="http://perl.jonallen.info">JJ</a>)</li>
68
<li class="spaced">Last updated on<br>23 April 2006</li>
71
<li class="spaced">Last updated on<br>23 December 2007</li>
69
72
<li class="spaced">See the <a href="http://perl.jonallen.info/projects/perldoc">project page</a> for
76
79
<div id="centerContent">
77
80
<div id="contentHeader">
78
81
<div id="contentHeaderLeft"><a href="#" onClick="showLeft()">Show navigation</a></div>
79
<div id="contentHeaderCentre">-- Perl 5.8.8 documentation --</div>
82
<div id="contentHeaderCentre">-- Perl 5.10.0 documentation --</div>
80
83
<div id="contentHeaderRight"><a href="#" onClick="showRight()">Show toolbar</a></div>
82
85
<div id="breadCrumbs"><a href="../index.html">Home</a> > <a href="../index-modules-A.html">Core modules</a> > <a href="../index-modules-L.html">L</a> > Locale::Country</div>
83
86
<script language="JavaScript">fromSearch();</script>
84
87
<div id="contentBody"><div class="title_container"><div class="page_title">Locale::Country</div></div><ul><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#CONVERSION-ROUTINES">CONVERSION ROUTINES</a><li><a href="#QUERY-ROUTINES">QUERY ROUTINES</a><li><a href="#SEMI-PRIVATE-ROUTINES">SEMI-PRIVATE ROUTINES</a><ul><li><a href="#alias_code">alias_code</a><li><a href="#rename_country">rename_country</a></ul><li><a href="#EXAMPLES">EXAMPLES</a><li><a href="#DOMAIN-NAMES">DOMAIN NAMES</a><li><a href="#KNOWN-BUGS-AND-LIMITATIONS">KNOWN BUGS AND LIMITATIONS</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#AUTHOR">AUTHOR</a><li><a href="#COPYRIGHT">COPYRIGHT</a></ul><a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
85
<pre class="verbatim"> <a class="l_k" href="../functions/use.html">use</a> <a class="l_w" href="../Locale/Country.html">Locale::Country</a><span class="sc">;</span>
87
<span class="i">$country</span> = <span class="i">code2country</span><span class="s">(</span><span class="q">'jp'</span><span class="s">)</span><span class="sc">;</span> <span class="c"># $country gets 'Japan'</span>
88
<span class="i">$code</span> = <span class="i">country2code</span><span class="s">(</span><span class="q">'Norway'</span><span class="s">)</span><span class="sc">;</span> <span class="c"># $code gets 'no'</span>
90
<span class="i">@codes</span> = <span class="i">all_country_codes</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span>
91
<span class="i">@names</span> = <span class="i">all_country_names</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span>
93
<span class="c"># semi-private routines</span>
88
<pre class="verbatim"> <a class="l_k" href="../functions/use.html">use</a> <span class="w">Locale::Country</span><span class="sc">;</span></pre>
89
<pre class="verbatim"> <span class="i">$country</span> = <span class="i">code2country</span><span class="s">(</span><span class="q">'jp'</span><span class="s">)</span><span class="sc">;</span> <span class="c"># $country gets 'Japan'</span>
90
<span class="i">$code</span> = <span class="i">country2code</span><span class="s">(</span><span class="q">'Norway'</span><span class="s">)</span><span class="sc">;</span> <span class="c"># $code gets 'no'</span></pre>
91
<pre class="verbatim"> <span class="i">@codes</span> = <span class="i">all_country_codes</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span>
92
<span class="i">@names</span> = <span class="i">all_country_names</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></pre>
93
<pre class="verbatim"> <span class="c"># semi-private routines</span>
94
94
<span class="i">Locale::Country::alias_code</span><span class="s">(</span><span class="q">'uk'</span> <span class="cm">=></span> <span class="q">'gb'</span><span class="s">)</span><span class="sc">;</span>
95
95
<span class="i">Locale::Country::rename_country</span><span class="s">(</span><span class="q">'gb'</span> <span class="cm">=></span> <span class="q">'Great Britain'</span><span class="s">)</span><span class="sc">;</span></pre>
96
96
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
97
<p>The <code class="inline"><a class="l_w" href="../Locale/Country.html">Locale::Country</a></code> module provides access to the ISO
97
<p>The <code class="inline"><span class="w">Locale::Country</span></code>
98
module provides access to the ISO
98
99
codes for identifying countries, as defined in ISO 3166-1.
99
100
You can either access the codes via the <a href="#conversion-routines">"conversion routines"</a>
100
101
(described below), or with the two functions which return lists
105
106
<li><a name="*alpha-2*"></a><b><b>alpha-2</b></b>
106
107
<p>Two letter codes, such as 'tv' for Tuvalu.
107
This code set is identified with the symbol <code class="inline">LOCALE_CODE_ALPHA_2</code>
108
This code set is identified with the symbol <code class="inline"><span class="w">LOCALE_CODE_ALPHA_2</span></code>
110
111
<li><a name="*alpha-3*"></a><b><b>alpha-3</b></b>
111
112
<p>Three letter codes, such as 'brb' for Barbados.
112
This code set is identified with the symbol <code class="inline">LOCALE_CODE_ALPHA_3</code>
113
This code set is identified with the symbol <code class="inline"><span class="w">LOCALE_CODE_ALPHA_3</span></code>
115
116
<li><a name="*numeric*"></a><b><b>numeric</b></b>
116
117
<p>Numeric codes, such as 064 for Bhutan.
117
This code set is identified with the symbol <code class="inline">LOCALE_CODE_NUMERIC</code>
118
This code set is identified with the symbol <code class="inline"><span class="w">LOCALE_CODE_NUMERIC</span></code>
133
134
is "us", so country2code('United States') returns 'us'.
134
135
Now the following will also return 'us':</p>
135
136
<pre class="verbatim"> country2code('United States of America')
136
country2code('USA') </pre><a name="CONVERSION-ROUTINES"></a><h1>CONVERSION ROUTINES</h1>
137
country2code('USA')</pre><a name="CONVERSION-ROUTINES"></a><h1>CONVERSION ROUTINES</h1>
137
138
<p>There are three conversion routines: <code class="inline"><span class="i">code2country</span><span class="s">(</span><span class="s">)</span></code>
138
139
, <code class="inline"><span class="i">country2code</span><span class="s">(</span><span class="s">)</span></code>
152
153
country code, if such exists.
153
154
If the argument could not be identified as a country name,
154
155
then <code class="inline"><a class="l_k" href="../functions/undef.html">undef</a></code> will be returned:</p>
155
<pre class="verbatim"> <span class="i">$code</span> = <span class="i">country2code</span><span class="s">(</span><span class="q">'Norway'</span><span class="cm">,</span> LOCALE_CODE_ALPHA_3<span class="s">)</span><span class="sc">;</span>
156
<pre class="verbatim"> <span class="i">$code</span> = <span class="i">country2code</span><span class="s">(</span><span class="q">'Norway'</span><span class="cm">,</span> <span class="w">LOCALE_CODE_ALPHA_3</span><span class="s">)</span><span class="sc">;</span>
156
157
<span class="c"># $code will now be 'nor'</span></pre>
157
158
<p>The case of the country name is not important.
158
159
See the section <a href="#KNOWN-BUGS-AND-LIMITATIONS">"KNOWN BUGS AND LIMITATIONS"</a> below.</p>
161
162
<p>This function takes a country code from one code set,
162
163
and returns the corresponding code from another code set.</p>
163
164
<pre class="verbatim"> <span class="i">$alpha2</span> = <span class="i">country_code2code</span><span class="s">(</span><span class="q">'fin'</span><span class="cm">,</span>
164
LOCALE_CODE_ALPHA_3<span class="cm">,</span> LOCALE_CODE_ALPHA_2<span class="s">)</span><span class="sc">;</span>
165
<span class="w">LOCALE_CODE_ALPHA_3</span><span class="cm">,</span> <span class="w">LOCALE_CODE_ALPHA_2</span><span class="s">)</span><span class="sc">;</span>
165
166
<span class="c"># $alpha2 will now be 'fi'</span></pre>
166
167
<p>If the code passed is not a valid country code in
167
168
the first code set, or if there isn't a code for the
173
174
<p>There are two function which can be used to obtain a list of all codes,
174
175
or all country names:</p>
176
<li><a name="'all_country_codes(-%5b-CODESET-%5d-)'"></a><b><code class="inline"><span class="i">all_country_codes</span><span class="s">(</span> <span class="s">[</span> CODESET <span class="s">]</span> <span class="s">)</span></code>
177
<li><a name="'all_country_codes(-%5b-CODESET-%5d-)'"></a><b><code class="inline"><span class="i">all_country_codes</span><span class="s">(</span> <span class="s">[</span> <span class="w">CODESET</span> <span class="s">]</span> <span class="s">)</span></code>
178
179
<p>Returns a list of all two-letter country codes.
179
180
The codes are guaranteed to be all lower-case,
180
181
and not in any particular order.</p>
182
<li><a name="'all_country_names(-%5b-CODESET-%5d-)'"></a><b><code class="inline"><span class="i">all_country_names</span><span class="s">(</span> <span class="s">[</span> CODESET <span class="s">]</span> <span class="s">)</span></code>
183
<li><a name="'all_country_names(-%5b-CODESET-%5d-)'"></a><b><code class="inline"><span class="i">all_country_names</span><span class="s">(</span> <span class="s">[</span> <span class="w">CODESET</span> <span class="s">]</span> <span class="s">)</span></code>
184
185
<p>Returns a list of all country names for which there is a corresponding
185
186
country code in the specified code set.
198
199
package name.</p>
199
200
<a name="alias_code"></a><h2>alias_code</h2>
200
201
<p>Define a new code as an alias for an existing code:</p>
201
<pre class="verbatim"> <span class="i">Locale::Country::alias_code</span><span class="s">(</span> ALIAS <span class="cm">=></span> CODE <span class="s">[</span><span class="cm">,</span> CODESET <span class="s">]</span> <span class="s">)</span></pre>
202
<pre class="verbatim"> <span class="i">Locale::Country::alias_code</span><span class="s">(</span> <span class="w">ALIAS</span> <span class="cm">=></span> <span class="w">CODE</span> <span class="s">[</span><span class="cm">,</span> <span class="w">CODESET</span> <span class="s">]</span> <span class="s">)</span></pre>
202
203
<p>This feature was added as a mechanism for handling
203
204
a "uk" code. The ISO standard says that the two-letter code for
204
205
"United Kingdom" is "gb", whereas domain names are all .uk.</p>
229
230
The user is prompted for a country code, and then told the corresponding
230
231
country name:</p>
231
<pre class="verbatim"> <span class="i">$|</span> = <span class="n">1</span><span class="sc">;</span> <span class="c"># turn off buffering</span>
233
<a class="l_k" href="../functions/print.html">print</a> <span class="q">"Enter country code: "</span><span class="sc">;</span>
232
<pre class="verbatim"> <span class="i">$|</span> = <span class="n">1</span><span class="sc">;</span> <span class="c"># turn off buffering</span></pre>
233
<pre class="verbatim"> <a class="l_k" href="../functions/print.html">print</a> <span class="q">"Enter country code: "</span><span class="sc">;</span>
234
234
<a class="l_k" href="../functions/chop.html">chop</a><span class="s">(</span><span class="i">$code</span> = <span class="q"><STDIN></span><span class="s">)</span><span class="sc">;</span>
235
<span class="i">$country</span> = <span class="i">code2country</span><span class="s">(</span><span class="i">$code</span><span class="cm">,</span> LOCALE_CODE_ALPHA_2<span class="s">)</span><span class="sc">;</span>
235
<span class="i">$country</span> = <span class="i">code2country</span><span class="s">(</span><span class="i">$code</span><span class="cm">,</span> <span class="w">LOCALE_CODE_ALPHA_2</span><span class="s">)</span><span class="sc">;</span>
236
236
if <span class="s">(</span><a class="l_k" href="../functions/defined.html">defined</a> <span class="i">$country</span><span class="s">)</span>
237
237
<span class="s">{</span>
238
238
<a class="l_k" href="../functions/print.html">print</a> <span class="q">"$code = $country\n"</span><span class="sc">;</span>