Geography::States is a Perl module with map states and provinces to their codes, and vice versa.
my $obj = Geography::States -> new (COUNTRY [, STRICT]);
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 code/name pairs.
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, The Netherlands, and Australia. 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.)