2-letter, 3-letter, and numerical codes for countries.
use Geography::Countries; $country = country 'DE'; # 'Germany' @list = country 666; # ('PM', 'SPM', 666, # 'Saint Pierre and Miquelon', 1)
This module maps country names, and their 2-letter, 3-letter and numerical codes, as defined by the \s-1ISO-3166\s0 maintenance agency [1], and defined by the \s-1UNSD\s0. This subroutine is exported by default. It takes a 2-letter, 3-letter or numerical code, or a country name as argument. In scalar context, it will return the country name, in list context, it will return a list consisting of the 2-letter code, the 3-letter code, the numerical code, the country name, and a flag, which is explained below. Note that not all countries have all 3 codes; if a code is unknown, the undefined value is returned.
There are 3 categories of countries. The largest category are the current countries. Then there is a small set of countries that no longer exist. The final set consists of areas consisting of multiple countries, like Africa. No 2-letter or 3-letter codes are available for the second two sets. (\s-1ISO\s0 3166-3 [3] defines 4 letter codes for the set of countries that no longer exist, but the author of this module was unable to get her hands on that standard.) By default, \*(C`country\*(C' only returns countries from the first set, but this can be changed by giving \*(C`country\*(C' an optional second argument.
The module optionally exports the constants \*(C`CNT_F_REGULAR\*(C', \*(C`CNT_F_OLD\*(C', \*(C`CNT_F_REGION\*(C' and \*(C`CNT_F_ANY\*(C'. These constants can also be important all at once by using the tag \*(C`:FLAGS\*(C'. \*(C`CNT_F_ANY\*(C' is just the binary or of the three other flags. The second argument of \*(C`country\*(C' should be the binary or of a subset of the flags \*(C`CNT_F_REGULAR\*(C', \*(C`CNT_F_OLD\*(C', and \*(C`CNT_F_REGION\*(C' - if no, or a false, second argument is given, \*(C`CNT_F_REGULAR\*(C' is assumed. If \*(C`CNT_F_REGULAR\*(C' is set, regular (current) countries will be returned; if \*(C`CNT_F_OLD\*(C' is set, old, no longer existing, countries will be returned, while \*(C`CNT_F_REGION\*(C' is used in case a region (not necessarely) a country might be returned. If \*(C`country\*(C' is used in list context, the fifth returned element is one of \*(C`CNT_F_REGULAR\*(C', \*(C`CNT_F_OLD\*(C' and \*(C`CNT_F_REGION\*(C', indicating whether the result is a regular country, an old country, or a region.
In list context, \*(C`country\*(C' returns a 5 element list. To avoid having to remember which element is in which index, the constants \*(C`CNT_I_CODE2\*(C', \*(C`CNT_I_CODE3\*(C', \*(C`CNT_I_NUMCODE\*(C', \*(C`CNT_I_COUNTRY\*(C' and \*(C`CNT_I_FLAG\*(C' can be imported. Those constants contain the indices of the 2-letter code, the 3-letter code, the numerical code, the country, and the flag explained above, respectively. All index constants can be imported by using the \*(C`:INDICES\*(C' tag. All known 2-letter codes, 3-letter codes, numerical codes and country names can be returned by the routines \*(C`code2\*(C', \*(C`code3\*(C', \*(C`numcode\*(C' and \*(C`countries\*(C'. None of these methods is exported by default; all need to be imported if one wants to use them. The tag \*(C`:LISTS\*(C' imports them all. In scalar context, the number of known codes or countries is returned.
The 2-letter codes come from the \s-1ISO\s0 3166-1:1997 standard [2]. \s-1ISO\s0 3166 bases its list of country names on the list of names published by the United Nations. This list is published by the Statistical Division of the United Nations [4]. The \s-1UNSD\s0 uses 3-letter codes, and numerical codes [5]. The information about old countries [6] and regions [7] also comes from the United Nations.
In a few cases, there was a conflict between the way how the United Nations spelled a name, and how \s-1ISO\s0 3166 spells it. In most cases, is was word order (for instance whether The republic of should preceed the name, or come after the name. A few cases had minor spelling variations. In all such cases, the method in which the \s-1UN\s0 spelled the name was choosen; \s-1ISO\s0 3166 claims to take the names from the \s-1UN\s0, so we consider the \s-1UN\s0 authoritative.
\s-1ISO\s0 Maintenance Agency (\s-1ISO\s0 3166/MA) http://www.din.de/gremien/nas/nabd/iso3166ma/index.html.
Country codes, http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1.html, 7 September 1999.
\s-1ISO\s0 3166-3, Code for formerly used country names. http://www.din.de/gremien/nas/nabd/iso3166ma/info_pt3.html.
United Nations, Statistics Division. http://www.un.org/Depts/unsd/statdiv.htm.
Country or area codes in alphabetical order. http://www.un.org/Depts/unsd/methods/m49alpha.htm, 26 August 1999.
Codes added or changed. http://www.un.org/Depts/unsd/methods/m49chang.htm, 26 August 1999.
Geographical regions. http://www.un.org/Depts/unsd/methods/m49regin.htm, 26 August 1999.
Looking up information using country names is far from perfect. Except for case and the amount of white space, the exact name as it appears on the list has to be given. \s-1USA\s0 will not return anything, but United States will.
The current sources of this module are found on github, git://github.com/Abigail/geography\*(--countries.git <git://github.com/Abigail/geography--countries.git>.
Abigail mailto:[email protected] <mailto:[email protected]>.
Copyright (C) 1999, 2009 by Abigail
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \*(L"Software\*(R"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
\s-1THE\s0 \s-1SOFTWARE\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R", \s-1WITHOUT\s0 \s-1WARRANTY\s0 \s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0, \s-1EXPRESS\s0 \s-1OR\s0 \s-1IMPLIED\s0, \s-1INCLUDING\s0 \s-1BUT\s0 \s-1NOT\s0 \s-1LIMITED\s0 \s-1TO\s0 \s-1THE\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \s-1MERCHANTABILITY\s0, \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0 \s-1AND\s0 \s-1NONINFRINGEMENT\s0. \s-1IN\s0 \s-1NO\s0 \s-1EVENT\s0 \s-1SHALL\s0 \s-1THE\s0 \s-1AUTHOR\s0 \s-1BE\s0 \s-1LIABLE\s0 \s-1FOR\s0 \s-1ANY\s0 \s-1CLAIM\s0, \s-1DAMAGES\s0 \s-1OR\s0 \s-1OTHER\s0 \s-1LIABILITY\s0, \s-1WHETHER\s0 \s-1IN\s0 \s-1AN\s0 \s-1ACTION\s0 \s-1OF\s0 \s-1CONTRACT\s0, \s-1TORT\s0 \s-1OR\s0 \s-1OTHERWISE\s0, \s-1ARISING\s0 \s-1FROM\s0, \s-1OUT\s0 \s-1OF\s0 \s-1OR\s0 \s-1IN\s0 \s-1CONNECTION\s0 \s-1WITH\s0 \s-1THE\s0 \s-1SOFTWARE\s0 \s-1OR\s0 \s-1THE\s0 \s-1USE\s0 \s-1OR\s0 \s-1OTHER\s0 \s-1DEALINGS\s0 \s-1IN\s0 \s-1THE\s0 \s-1SOFTWARE\s0.