Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2023-12-02 06:30 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (13 votes). Check out past polls.