NAME
Geography::States -- Map states and provinces to their codes, and vica versa.
SYNOPSIS
use Geography::States;
my $obj = Geography::States -> new (COUNTRY [, STRICT]);
EXAMPLES
my $canada = Geography::States -> new ('Canada');
my $name = $canada -> state 'NF'; # Newfoundland.
my $code = $canada -> state 'Ontario'; # ON.
my ($code, $name) = $canada -> state 'BC'; # BC, British Columbia.
my @all_states = $canada -> state; # List of code/name pairs.
DESCRIPTION
This module lets you map states and provinces to their codes, and codes to names of provinces and states.
The Geography::States -
new ()> call takes 1 or 2 arguments. The first, required, argument is the country we are interested in. Current supported countries are USA, Brazil, Canada, and The Netherlands. If a second non-false argument is given, we use strict mode. In non-strict mode, we will map territories and alternative codes as well, while we do not do that in strict mode. For example, if the country is USA, in non-strict mode, we will map GU to Guam, while in strict mode, neither GU and Guam will be found.
The state() method
All queries are done by calling the state
method in the object. This method takes an optional argument. If an argument is given, then in scalar context, it will return the name of the state if a code of a state is given, and the code of a state, if the argument of the method is a name of a state. In list context, both the code and the state will be returned.
If no argument is given, then the state
method in list context will return a list of all code/name pairs for that country. In scalar context, it will return the number of code/name pairs. Each code/name pair is a 2 element anonymous array.
Arguments can be given in a case insensitive way; if a name consists of multiple parts, the number of spaces does not matter, as long as there is some whitespace. (That is "NewYork" is wrong, but "new YORK" is fine.)
ODDITIES AND OPEN QUESTIONS
I found conflicting abbreviations for the US Northern Mariana Islands, listed as NI and MP. I picked MP from the USPS site.
One site listed Midway Islands as having code MD. It is not listed by the USPS site, and because it conflicts with Maryland, it is not put in this listing.
The USPS also has so-called Military "States", with non-unique codes. Those are not listed here.
Canada's Quebec has two codes, the older PQ and the modern QC. Both PQ and QC will map to Quebec, but Quebec will only map to QC. With strict mode, PQ will not be listed.
REVISION HISTORY
$Log: States.pm,v $
Revision 1.2 1999/09/10 17:12:05 abigail
Added a 'require 5.005' due to the use of INIT.
Revision 1.1 1999/09/09 07:33:54 abigail
Initial revision
AUTHOR
This package was written by Abigail, abigail@delanet.com.
COPYRIGHT and LICENSE
This package is copyright 1999 by Abigail.
This program is free and open software. You may use, copy, modify, distribute and sell this program (and any modified variants) in any way you wish, provided you do not restrict others to do the same.