Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thanks for pointing out the now standard Locale::Country. I've modified it to get the data from it.
package Locale::Country::TieHash; use 5.002; use strict; use warnings; use Tie::Hash; use Carp; use Locale::Country; our $VERSION = '0.01'; our @ISA = qw(Tie::StdHash); my %CountryHash = (); sub TIEHASH { my $class = shift; my $self = {}; my @countries = all_country_codes(); foreach my $country (@countries){ $CountryHash{$country} = "\U$country ".code2country($count +ry); $CountryHash{lc(code2country($country))} = "\U$country ".c +ode2country($country); } $self->{DAT} = \%CountryHash; $self->{keys} = \@countries; $self->{key_index} = 0; return bless $self, $class; } sub STORE { my ($self, $key, $value) = @_; croak __PACKAGE__,":Cannot set value for $key! READ-ONLY"; } sub DELETE { my ($self, $key, $value) = @_; croak __PACKAGE__,":Cannot delete value for $key! READ-ONLY"; } sub FETCH { my ($self, $key) = @_; $key=~/^(\w\w)\s/; my $ikey = lc($1 || $key); return $self->{DAT}{lc $ikey}; } sub EXISTS { my ($self, $key) = @_; $key=~/^(\w\w)\s/; my $ikey = lc($1 || $key); return exists $self->{DAT}{lc $ikey}; } sub DEFINED { my ($self, $key) = @_; $key=~/^(\w\w)\s/; my $ikey = lc($1 || $key); return defined $self->{DAT}{lc $ikey}; } sub FIRSTKEY { my $self = shift; $self->{key_index} = 0; return $self->{DAT}{ $self->{keys}->[$self->{key_index}++] }; } sub NEXTKEY { my $self = shift; return undef unless defined($self->{keys}[ $self->{key_index}]); return $self->{DAT}{$self->{keys}[ $self->{key_index}++] }; } sub CLEAR { croak __PACKAGE__,":Cannot clear Country Hash! READ-ONLY"; } 1; __END__ # Below is stub documentation for your module. You better edit it! =head1 NAME WWE::Country::ISO - Perl extension for Validating Country codes via ti +ed-hash =head1 SYNOPSIS use Locale::Country::TieHash; tie %Countries, 'Locale::Country::TieHash'; =head1 DESCRIPTION use Locale::Country::TieHash; tie %Countries, 'Locale::Country::TieHash' or die "Couldn't tie"; my $country = "United StAtes"; die "Invalid $country" unless exists($Countries{$country}); print $Countries{'Us'},"\n"; # Prints US United + States print $Countries{'Us UnitEd StateS'},"\n"; # Prints US United S +tates print $Countries{'United States'},"\n"; # Prints US United +States my @states = keys %Countries; # Returns ISO 3166 + names sorted. Let's you look up countries by ISO 3166 Alpha-2abbreviations, Country +name and ISO 3166 country name. (Case-insensitive) Exists and defined work as you would expect. Use at your own risk :) =head2 EXPORT None by default. =head1 AUTHOR Pumphret, Lee, E<lt><gt> =head1 COPYRIGHT Copyright (C) 2002 Lee Pumphret All Rights Reserved. This module is free software; you can redistribute it and/or modify it + under the same terms as Perl itself. =head1 SEE ALSO Locale::Country L<perl>. =cut


"To be civilized is to deny one's nature."

In reply to Re: (2): New Validate ISO 3166 by shotgunefx
in thread Validate Country by ISO 3166 data by shotgunefx

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2020-04-06 19:08 GMT
    Find Nodes?
      Voting Booth?
      The most amusing oxymoron is:

      Results (41 votes). Check out past polls.