File: split_gnis.pl

package info (click to toggle)
xastir 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,284 kB
  • sloc: ansic: 119,926; perl: 7,810; sh: 1,309; makefile: 392; sql: 102
file content (35 lines) | stat: -rwxr-xr-x 772 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl
use warnings;
#
#
# split_gnis.pl -- 2004 Mar 15 -- jmt@twilley.org

# This script is designed to break large GNIS datapoint files
# into smaller chunks and will dispose of extra whitespace properly.

# It is based on a bash script written by kc9asi@arrl.net.

# The filenames used as input should be put on the command line.


while (<>) {
  next unless /[A-Z][a-z]/;
  s/\s+$//;
  my $line = $_;
  my @fields = split /\|/, $line;
#  print "Fields is @fields\n";
  # key is "state county"
  my $key = $fields[1] . " " . $fields[4];
  $key =~ s/ /_/g;
  push @{$county{$key}}, $line;
}

foreach $elem (keys %county) {
  my $name = $elem . ".gnis";
  open(OUT,">$name");
  foreach $line (@{$county{$elem}}) {
    print OUT $line, "\n";
  }
  close(OUT);
}