Kind of a terribly ineffecient way of going about things given there is already a country code conversion class that comes with perl. Locale::Country already has this functionality, but in addition, it also supplies reverse functionality (country name -> code mapping), as well as arrays of all the codes.
Here's an example app I whipped up in a couple minutes:
Code:#!/usr/bin/perl use strict; use Locale::Country; my ($code, $country); $code = $ARGV[0]; if (length($code) < 1) { print "Please supply a country code.\n"; exit; } chomp($code); $country = code2country($code); if (defined $country) { print "Code '$code' is $country\n"; } else { print "'$code' is not a valid country code!\n"; }




Reply With Quote