Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

(dkubb) Re: (2) U.S. State Names

by dkubb (Deacon)
on Feb 26, 2001 at 08:49 UTC ( [id://60817]=note: print w/replies, xml ) Need Help??


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
    Awesome point dkubb! I would never have thought of using that module to do that same thing tye was doing earlier on his own. This saves us a ton of time! Thanks for bringing this module up and letting us know about it! :-)

    bladx ~ ¡mucho veces yo tengo preguntas!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://60817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found