Stereonaut!

Net::Domain::ES::ccTLD
~ Sep 1, 2009

with one comment

As I'm rewriting the core of Planeta Linux (you can track progress here), I needed a reliable way to map a country TLD to its Spanish name. I headed to CPAN to see what was already built to do that and found out Locales::Country that looked awesome but it didn't work for me, code2country('ni') would return undef for me, plus the countries that were actually there had the encoding all fubar, so fuck it, drop it.

So I came up with Net::Domain::ES::ccTLD using the data from the Spanish Wikipedia for the countries TLDs:

use Net::Domain::ES::ccTLD;

my $country = find_name_by_cctld('mx')     # $country is 'México'
  or die "Couldn't find name.";

my $current = find_name_by_cctld('us');    # $current is 'Estados Unidos';

Why would I reinvent the wheel for this? Because it was easier and faster for me and it's all about practicality, isn't it? Plus the code is super tiny, maybe the smallest module I have in CPAN in terms of actual code.

Feel free to use if you will.

Written by David Moreno

September 1st, 2009 at 3:28 pm

Categorized in: perl, planeta linux

Tagged with , , , , ,

One Response to 'Net::Domain::ES::ccTLD'

Subscribe to comments with RSS or TrackBack to 'Net::Domain::ES::ccTLD'.

  1. May I point you to Locale::Country::Multilingual?
    It uses ISO 3166 codes rather than ccTLDs, but those are normally the same – there are only a few (6) exceptions: http://en.wikipedia.org/wiki/Country_code_top-level_domain#ccTLDs_not_in_ISO_3166-1.

    Bernhard Graf

    2 Sep 09 at 12:34 am

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes