You can ofcourse use pure-perl library too.
Here is an working script:
#!/usr/bin/env perl
use 5.014;
use warnings;
use Number::Phone::Country;
use Locale::Country;
for my $arg (@ARGV) {
#get ISO country code and IDD from the number
my($iso_cc, $idd) = Number::Phone::Country::phone2country_and_idd($arg);
unless($iso_cc) {
warn "Bad phone number $arg";
next;
}
say "Phone: $arg";
say "ISO Code: $iso_cc";
say "International direct dialing: $idd";
#get the country name from the ISO code
my $country = code2country($iso_cc);
say "Country name: $country\n";
}
If you run it as:
perl scriptname "+1 302 1234567" +421905905905
outputs:
Phone: +1 302 1234567
ISO Code: US
International direct dialing: 1
Country name: United States
Phone: +421905905905
ISO Code: SK
International direct dialing: 421
Country name: Slovakia
The script uses two perl modules: