countries: preliminary script to recreate include
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 1 Feb 2015 07:00:32 +0000 (08:00 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 1 Feb 2015 17:34:50 +0000 (18:34 +0100)
Parse Wikipedia page to compare output to current data.
Lacks insular and reserved codes.

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

diff --git a/tools/mkcountries-wikipedia b/tools/mkcountries-wikipedia
new file mode 100755 (executable)
index 0000000..67916dc
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+use 5.012;
+use warnings;
+
+my %cc;  # map of country code to info array
+
+while (<>) {
+       /<pre>/ .. /<\/pre>/ or next;  # data is in preformatted block
+       m{
+               \A (?<continent> [A-Z]{2})
+               \h (?<codea2> [A-Z]{2})
+               \h \S* \h \d*  # skip other iso codes
+               \h (?<name> .+)
+       }x or next;
+       $cc{ lc $+{codea2} } = [ $+{name}, "c-\L$+{continent}" ];
+}
+
+use Data::Dump 'dd';
+$Data::Dump::INDENT = '';
+dd \%cc;
+
+__END__
+
+=head1 NAME
+
+mkcountryinfo - Create Perl include of country info from Wikipedia page
+
+=head1 SYNOPSIS
+
+       curl http://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent_%28data_file%29 |
+       tools/mkcountryinfo > countries.inc.pl
+