countries: script to create include from geonames data
[sheet.git] / tools / mkcountries-geonames
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         /^#/ and next;  # skip comments
9         my ($iso, $name, $cont) = (split /\t/)[0, 4, 8];
10         my $class = "c-\L$cont";
11         $cc{ lc $iso } = [ $name, $class ];
12 }
13
14 say "# automatically generated by $0";
15 use Data::Dump 'dd';
16 $Data::Dump::INDENT = '';
17 dd \%cc;
18
19 __END__
20
21 =head1 NAME
22
23 mkcountries-geonames - Create Perl include of country info from GeoNames data
24
25 =head1 SYNOPSIS
26
27         curl http://download.geonames.org/export/dump/countryInfo.txt |
28         tools/mkcountryinfo > countries.inc.pl
29