countries: script to create include from geonames data
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 1 Feb 2015 07:06:51 +0000 (08:06 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 1 Feb 2015 17:34:50 +0000 (18:34 +0100)
Great source which seems much more maintained than the outdated
Locale::Object database used, and contains most wanted information
(continents), except unfortunately missing reserved codes.

tools/mkcountries-geonames [new file with mode: 0755]

diff --git a/tools/mkcountries-geonames b/tools/mkcountries-geonames
new file mode 100755 (executable)
index 0000000..0eaf880
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use 5.012;
+use warnings;
+
+my %cc;  # map of country code to info array
+
+while (<>) {
+       /^#/ and next;  # skip comments
+       my ($iso, $name, $cont) = (split /\t/)[0, 4, 8];
+       my $class = "c-\L$cont";
+       $cc{ lc $iso } = [ $name, $class ];
+}
+
+say "# automatically generated by $0";
+use Data::Dump 'dd';
+$Data::Dump::INDENT = '';
+dd \%cc;
+
+__END__
+
+=head1 NAME
+
+mkcountries-geonames - Create Perl include of country info from GeoNames data
+
+=head1 SYNOPSIS
+
+       curl http://download.geonames.org/export/dump/countryInfo.txt |
+       tools/mkcountryinfo > countries.inc.pl
+