countries: hardcode codes reserved for WIPO
[sheet.git] / tools / mkcountries-wikipedia
1 #!/usr/bin/env perl
2 use 5.012;
3 use warnings;
4
5 my %cc;  # map of country code to info array
6
7 while (<>) {
8         /<pre>/ .. /<\/pre>/ or next;  # data is in preformatted block
9         m{
10                 \A (?<continent> [A-Z]{2})
11                 \h (?<codea2> [A-Z]{2})
12                 \h \S* \h \d*  # skip other iso codes
13                 \h (?<name> .+)
14         }x or next;
15         $cc{ lc $+{codea2} } = [ $+{name}, "c-\L$+{continent}" ];
16 }
17
18 use Data::Dump 'dd';
19 $Data::Dump::INDENT = '';
20 dd \%cc;
21
22 __END__
23
24 =head1 NAME
25
26 mkcountryinfo - Create Perl include of country info from Wikipedia page
27
28 =head1 SYNOPSIS
29
30         curl http://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent_%28data_file%29 |
31         tools/mkcountryinfo > countries.inc.pl
32