in reply to U.S. State Names
An alternate way to get the United States' state names is by using the CPAN module Locale::SubCountry:
#!/usr/bin/perl -w use strict; use Locale::SubCountry; use Data::Dumper qw(Dumper); #Create an object representing a certain country my $subcountry = Locale::SubCountry->new('US'); #Query to find this country's subcountries. my %states = $subcountry->code_full_name_hash; #Prints the name/code pairs for every US state print Dumper(\%states); __END__
Besides the obvious benefit of keeping these details in a central location, this module will tell you the state/province/county/etc of all the countries in the ISO 3166-2 sub country code list.
Updated: I changed the code example to use the method code_full_name_hash which returns a hash where the state code is the key and the value is the state's full name. This is so my example returns the same as tye's first example.
The method name was self describing, if you'd like the reverse (like I had before), use the full_name_code method.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (dkubb) Re: (2) U.S. State Names
by bladx (Chaplain) on Feb 26, 2001 at 10:34 UTC |
In Section
Snippets Section