.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "COUNTRY 1"
.TH COUNTRY 1 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
Locale::Country \- ISO codes for country identification (ISO 3166)
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Locale::Country;
.Ve
.PP
.Vb 2
\& $country = code2country('jp'); # $country gets 'Japan'
\& $code = country2code('Norway'); # $code gets 'no'
.Ve
.PP
.Vb 2
\& @codes = all_country_codes();
\& @names = all_country_names();
.Ve
.PP
.Vb 3
\& # semi-private routines
\& Locale::Country::alias_code('uk' => 'gb');
\& Locale::Country::rename_country('gb' => 'Great Britain');
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \f(CW\*(C`Locale::Country\*(C'\fR module provides access to the \s-1ISO\s0
codes for identifying countries, as defined in \s-1ISO\s0 3166\-1.
You can either access the codes via the \*(L"conversion routines\*(R"
(described below), or with the two functions which return lists
of all country codes or all country names.
.PP
There are three different code sets you can use for identifying
countries:
.IP "\fBalpha\-2\fR" 4
.IX Item "alpha-2"
Two letter codes, such as 'tv' for Tuvalu.
This code set is identified with the symbol \f(CW\*(C`LOCALE_CODE_ALPHA_2\*(C'\fR.
.IP "\fBalpha\-3\fR" 4
.IX Item "alpha-3"
Three letter codes, such as 'brb' for Barbados.
This code set is identified with the symbol \f(CW\*(C`LOCALE_CODE_ALPHA_3\*(C'\fR.
.IP "\fBnumeric\fR" 4
.IX Item "numeric"
Numeric codes, such as 064 for Bhutan.
This code set is identified with the symbol \f(CW\*(C`LOCALE_CODE_NUMERIC\*(C'\fR.
.PP
All of the routines take an optional additional argument
which specifies the code set to use.
If not specified, it defaults to the two-letter codes.
This is partly for backwards compatibility (previous versions
of this module only supported the alpha\-2 codes), and
partly because they are the most widely used codes.
.PP
The alpha\-2 and alpha\-3 codes are not case\-dependent,
so you can use '\s-1BO\s0', 'Bo', 'bO' or 'bo' for Bolivia.
When a code is returned by one of the functions in
this module, it will always be lower\-case.
.PP
As of version 2.00, Locale::Country supports variant
names for countries. So, for example, the country code for \*(L"United States\*(R"
is \*(L"us\*(R", so country2code('United States') returns 'us'.
Now the following will also return 'us':
.PP
.Vb 2
\& country2code('United States of America')
\& country2code('USA')
.Ve
.SH "CONVERSION ROUTINES"
.IX Header "CONVERSION ROUTINES"
There are three conversion routines: \f(CW\*(C`code2country()\*(C'\fR, \f(CW\*(C`country2code()\*(C'\fR,
and \f(CW\*(C`country_code2code()\*(C'\fR.
.IP "code2country( \s-1CODE\s0, [ \s-1CODESET\s0 ] )" 4
.IX Item "code2country( CODE, [ CODESET ] )"
This function takes a country code and returns a string
which contains the name of the country identified.
If the code is not a valid country code, as defined by \s-1ISO\s0 3166,
then \f(CW\*(C`undef\*(C'\fR will be returned:
.Sp
.Vb 1
\& $country = code2country('fi');
.Ve
.IP "country2code( \s-1STRING\s0, [ \s-1CODESET\s0 ] )" 4
.IX Item "country2code( STRING, [ CODESET ] )"
This function takes a country name and returns the corresponding
country code, if such exists.
If the argument could not be identified as a country name,
then \f(CW\*(C`undef\*(C'\fR will be returned:
.Sp
.Vb 2
\& $code = country2code('Norway', LOCALE_CODE_ALPHA_3);
\& # $code will now be 'nor'
.Ve
.Sp
The case of the country name is not important.
See the section \*(L"\s-1KNOWN\s0 \s-1BUGS\s0 \s-1AND\s0 \s-1LIMITATIONS\s0\*(R" below.
.IP "country_code2code( \s-1CODE\s0, \s-1CODESET\s0, \s-1CODESET\s0 )" 4
.IX Item "country_code2code( CODE, CODESET, CODESET )"
This function takes a country code from one code set,
and returns the corresponding code from another code set.
.Sp
.Vb 3
\& $alpha2 = country_code2code('fin',
\& LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2);
\& # $alpha2 will now be 'fi'
.Ve
.Sp
If the code passed is not a valid country code in
the first code set, or if there isn't a code for the
corresponding country in the second code set,
then \f(CW\*(C`undef\*(C'\fR will be returned.
.SH "QUERY ROUTINES"
.IX Header "QUERY ROUTINES"
There are two function which can be used to obtain a list of all codes,
or all country names:
.ie n .IP """all_country_codes( [ CODESET ] )""" 4
.el .IP "\f(CWall_country_codes( [ CODESET ] )\fR" 4
.IX Item "all_country_codes( [ CODESET ] )"
Returns a list of all two-letter country codes.
The codes are guaranteed to be all lower\-case,
and not in any particular order.
.ie n .IP """all_country_names( [ CODESET ] )""" 4
.el .IP "\f(CWall_country_names( [ CODESET ] )\fR" 4
.IX Item "all_country_names( [ CODESET ] )"
Returns a list of all country names for which there is a corresponding
country code in the specified code set.
The names are capitalised, and not returned in any particular order.
.Sp
Not all countries have alpha\-3 and numeric codes \-
some just have an alpha\-2 code,
so you'll get a different number of countries
depending on which code set you specify.
.SH "SEMI-PRIVATE ROUTINES"
.IX Header "SEMI-PRIVATE ROUTINES"
Locale::Country provides two semi-private routines for modifying
the internal data.
Given their status, they aren't exported by default,
and so need to be called by prefixing the function name with the
package name.
.Sh "alias_code"
.IX Subsection "alias_code"
Define a new code as an alias for an existing code:
.PP
.Vb 1
\& Locale::Country::alias_code( ALIAS => CODE [, CODESET ] )
.Ve
.PP
This feature was added as a mechanism for handling
a \*(L"uk\*(R" code. The \s-1ISO\s0 standard says that the two-letter code for
\&\*(L"United Kingdom\*(R" is \*(L"gb\*(R", whereas domain names are all .uk.
.PP
By default the module does not understand \*(L"uk\*(R", since it is implementing
an \s-1ISO\s0 standard. If you would like 'uk' to work as the two-letter
code for United Kingdom, use the following:
.PP
.Vb 1
\& Locale::Country::alias_code('uk' => 'gb');
.Ve
.PP
With this code, both \*(L"uk\*(R" and \*(L"gb\*(R" are valid codes for United Kingdom,
with the reverse lookup returning \*(L"uk\*(R" rather than the usual \*(L"gb\*(R".
.PP
\&\fBNote:\fR this function was previously called _alias_code,
but the leading underscore has been dropped.
The old name will be supported for all 2.X releases for
backwards compatibility.
.Sh "rename_country"
.IX Subsection "rename_country"
If the official country name just isn't good enough for you,
you can rename a country. For example, the official country
name for code 'gb' is 'United Kingdom'.
If you want to change that, you might call:
.PP
.Vb 1
\& Locale::Country::rename_country('gb' => 'Great Britain');
.Ve
.PP
This means that calling code2country('gb') will now return
\&'Great Britain' instead of 'United Kingdom'.
The original country name is retained as an alias,
so for the above example, country2code('United Kingdom')
will still return 'gb'.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
The following example illustrates use of the \f(CW\*(C`code2country()\*(C'\fR function.
The user is prompted for a country code, and then told the corresponding
country name:
.PP
.Vb 1
\& $| = 1; # turn off buffering
.Ve
.PP
.Vb 11
\& print "Enter country code: ";
\& chop($code = <STDIN>);
\& $country = code2country($code, LOCALE_CODE_ALPHA_2);
\& if (defined $country)
\& {
\& print "$code = $country\en";
\& }
\& else
\& {
\& print "'$code' is not a valid country code!\en";
\& }
.Ve
.SH "DOMAIN NAMES"
.IX Header "DOMAIN NAMES"
Most top-level domain names are based on these codes,
but there are certain codes which aren't.
If you are using this module to identify country from hostname,
your best bet is to preprocess the country code.
.PP
For example, \fBedu\fR, \fBcom\fR, \fBgov\fR and friends would map to \fBus\fR;
\&\fBuk\fR would map to \fBgb\fR. Any others?
.SH "KNOWN BUGS AND LIMITATIONS"
.IX Header "KNOWN BUGS AND LIMITATIONS"
.IP "\(bu" 4
When using \f(CW\*(C`country2code()\*(C'\fR, the country name must currently appear
exactly as it does in the source of the module. The module now supports
a small number of variants.
.Sp
Possible extensions to this are: an interface for getting at the
list of variant names, and regular expression matches.
.IP "\(bu" 4
In the current implementation, all data is read in when the
module is loaded, and then held in memory.
A lazy implementation would be more memory friendly.
.IP "\(bu" 4
Support for country names in different languages.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP "Locale::Language" 4
.IX Item "Locale::Language"
\&\s-1ISO\s0 two letter codes for identification of language (\s-1ISO\s0 639).
.IP "Locale::Script" 4
.IX Item "Locale::Script"
\&\s-1ISO\s0 codes for identification of scripts (\s-1ISO\s0 15924).
.IP "Locale::Currency" 4
.IX Item "Locale::Currency"
\&\s-1ISO\s0 three letter codes for identification of currencies
and funds (\s-1ISO\s0 4217).
.IP "Locale::SubCountry" 4
.IX Item "Locale::SubCountry"
\&\s-1ISO\s0 codes for country sub-divisions (states, counties, provinces, etc),
as defined in \s-1ISO\s0 3166\-2.
This module is not part of the Locale-Codes distribution,
but is available from \s-1CPAN\s0 in CPAN/modules/by\-module/Locale/
.IP "\s-1ISO\s0 3166\-1" 4
.IX Item "ISO 3166-1"
The \s-1ISO\s0 standard which defines these codes.
.IP "http://www.iso.org/iso/en/prods\-services/iso3166ma/index.html" 4
.IX Item "http://www.iso.org/iso/en/prods-services/iso3166ma/index.html"
Official home page for the \s-1ISO\s0 3166 maintenance agency.
.IP "http://www.egt.ie/standards/iso3166/iso3166\-1\-en.html" 4
.IX Item "http://www.egt.ie/standards/iso3166/iso3166-1-en.html"
Another useful, but not official, home page.
.IP "http://www.cia.gov/cia/publications/factbook/docs/app\-d\-1.html" 4
.IX Item "http://www.cia.gov/cia/publications/factbook/docs/app-d-1.html"
An appendix in the \s-1CIA\s0 world fact book which lists country codes
as defined by \s-1ISO\s0 3166, \s-1FIPS\s0 10\-4, and internet domain names.
.SH "AUTHOR"
.IX Header "AUTHOR"
Neil Bowers <neil@bowers.com>
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (C) 2002, Neil Bowers.
.PP
Copyright (c) 1997\-2001 Canon Research Centre Europe (\s-1CRE\s0).
.PP
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
|