Geo::GNS::Parser - parse a GNS data file
use Geo::GNS::Parser 'parse_file'; my $in_file = 'ja.txt'; my %lines; my $n_entries; my $n_places; parse_file (file => $in_file, callback => \& callback); print "$n_entries / $n_places\n"; exit; sub callback { my (undef, $line) = @_; $n_entries++; my @parts = split /\t/, $_; my $ufi = $line->{UFI}; if (my $e = $lines{$ufi}) { print "Duplicate $ufi for $line->{FULL_NAME_RO} $e->{FULL_NAME_RO}\n"; } else { $lines{$ufi} = $line; $n_places++; } }
(This example is included as synopsis.pl in the distribution.)
This documents Geo::GNS::Parser version 0.02 corresponding to git commit dd93949b220dd7e8072228a93cebac75b6b536d3 released on Thu Jul 13 08:37:47 2017 +0900.
Parse the GeoNET Names Server data
parse_file (file => 'ja.txt', data => \@array);
Parse the data in the file specified by file and put the lines into the array specified by the data parameter. Each line is added to the array as a hash reference with the keys given under "FIELDS", and the values taken from the read line.
file
data
parse_file (file => 'af.txt', callback => \& myroutine);
Parse the data in the file specified by file. As each line of data is parsed, call back the code routine specified by callback. The callback is called in the form
callback
&{callback} (undef, \%line);
Possible options are
The file name. This must be supplied or the module dies.
An array reference.
A code reference to call back. If parse_file is called as
parse_file (%inputs);
then the callback is called in the form
&{$inputs{callback}} ($inputs{callback_data}, \%line);
where %line is a hash containing the parts of the line as specified under "FIELDS".
%line
User-specified data to pass to the callback routine. See "callback" above.
The fields in the data are as follows. The meanings of each field are explained at http://geonames.nga.mil/gns/html/gis_countryfiles.html.
http://geonames.nga.mil/gns/html/
Geolocator is a Python project using this data.
As of 0.02, I am not aware of any other CPAN module which parses the GeoNET data. The following modules are related to geography.
I proposed this module in 2012 on PrePAN: http://prepan.org/module/429En4oFbE.
I released this module to CPAN in July 2017.
Ben Bullock, <bkb@cpan.org>
This package and associated files are copyright (C) 2012-2017 Ben Bullock.
You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.
To install Geo::GNS::Parser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::GNS::Parser
CPAN shell
perl -MCPAN -e shell install Geo::GNS::Parser
For more information on module installation, please visit the detailed CPAN module installation guide.