1#!/usr/local/bin/perl 2use warnings; 3# 4# 5# split_gnis.pl -- 2004 Mar 15 -- jmt@twilley.org 6 7# This script is designed to break large GNIS datapoint files 8# into smaller chunks and will dispose of extra whitespace properly. 9 10# It is based on a bash script written by kc9asi@arrl.net. 11 12# The filenames used as input should be put on the command line. 13 14 15while (<>) { 16 next unless /[A-Z][a-z]/; 17 s/\s+$//; 18 my $line = $_; 19 my @fields = split /\|/, $line; 20# print "Fields is @fields\n"; 21 # key is "state county" 22 my $key = $fields[1] . " " . $fields[4]; 23 $key =~ s/ /_/g; 24 push @{$county{$key}}, $line; 25} 26 27foreach $elem (keys %county) { 28 my $name = $elem . ".gnis"; 29 open(OUT,">$name"); 30 foreach $line (@{$county{$elem}}) { 31 print OUT $line, "\n"; 32 } 33 close(OUT); 34} 35 36