Locale::US(3pm)

πŸ“¦
version 3.04 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Locale::US β€” the manual, but make it make sense πŸ’–

okay bestie, so this is Locale::US, a Perl module (a 3pm page, if we're being specific) and it does exactly one iconic thing: it knows every US state's two-letter code and every state name, and it can flip between them in both directions. No cap. That's the whole vibe. state identification in the United States and vice versa ✨


✨ SYNOPSIS ✨

here's the whole thing, copy it, it's giving copy-paste energy:

use Locale::US;

my $u = Locale::US->new;

my $state = $u->{code2state}{$code};
my $code  = $u->{state2code}{$state};

my @state = $u->all_state_names;
my @code  = $u->all_state_codes;

🌸 ABSTRACT 🌸

It's a map, babes. US two-letter codes β†’ states, and states β†’ two-letter codes. Both ways. Slay.


πŸ’… DESCRIPTION πŸ’…

πŸ—ΊοΈ MAPPING

  • $self->{code2state} β€” a hashref where the key is the two-letter state name and the value is the long name. So you look up by code, you get the whole government name back. πŸ’–
  • $self->{state2code} β€” a hashref where the key is the long name and the value is the two-letter state name. Reverse it, flip it, turn it around. πŸ”„

πŸŽ€ DUMPING

  • $self->all_state_names β€” returns an array (NOT an arrayref, bestie, an actual @array) of all the state names, in alphabetical form. πŸ“š
  • $self->all_state_codes β€” returns an array (again, NOT an arrayref) of all the state codes, in alphabetical form. πŸ”€

πŸ’€ KNOWN BUGS AND LIMITATIONS πŸ’€

listen, we love her, but she has flaws:

  • The state name comes back in uc() format. That's the uppercase thing, iykyk. 😭
  • neither hash is strict, though they should be. fr fr, they should be. πŸ™ˆ

πŸ”₯ SEE ALSO πŸ”₯

🌍 Locale::Country

Locale::Country β€” go check it out, it's the international cousin.

πŸ”— Abbreviations

<http://www.usps.gov/ncsc/lookups/usps_abbreviations.htm>

Online file with the USPS two-letter codes for the United States and its possessions.

πŸ› οΈ AUXILIARY CODE:

lynx -dump http://www.usps.gov/ncsc/lookups/usps_abbreviations.htm > kruft.txt
kruft2codes.pl

πŸ‘‘ AUTHOR πŸ‘‘

Currently maintained by Mike Accardo, <accardo@cpan.org>

Original author T. M. Brannon

🩹 PATCHES

Thanks to stevet AT ibrinc for a patch about second call to new failing. 🫢


Copyright (c) 2015 Mike Accardo
Copyright (c) 2002-2014 Terrence Brannon

All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Periodt. βœ…


kay that's the whole page, bestie!! πŸ’–βœ¨ this gorgeous thing was pulled from perl v5.36.0, dated 2022-11-19, and it lives at Locale::US(3pm) β€” go read a state code, you deserve it πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from