#!/usr/bin/perl # road_names --- # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.html # Created: 2023-09-24T10:06:26+0000 # Last-Updated: 2023-09-24T10:07:09+0000 # Update #: 2 #Otero County Colorado USA road name letters and numbers, derived from their position in the address grid. #Input: lines that end in 12000E, 8000N etc. #Output: tack road name letters/ numbers on back of input. use strict; use warnings FATAL => "all"; my $numbers_per_letter = 1000; my $lowest = 1000; my @letters; for my $r ( 1 .. 3 ) { #Start at 1=A, not 0. for ( q(A) .. q(Z) ) { next if /[IOQ]/; push @letters, $_ x $r; } # last; #Actually, for the part of the county we are doing, up to the correction line, #we don't need that many letters. } unshift @letters, undef; #Addresses start at 1000E. while (<>) { if ( $. == 1 && !/\d/ ) { print; next; } #Header chomp; m!([-\d.]+)([NWSE]+)$! or die "No address on this line: $_"; my $s = "$_(CR " . f( $1, $2 ) . ")\n"; print $s; #to die cleanly. } sub f { my ( $number, $direction ) = @_; die "Must be in NE quadrant" if $direction !~ /[NE]/; die "$number: Lowest address in this county is $lowest" if $number < $lowest; my $st = sprintf "%.2f", $number / $numbers_per_letter; if ( $direction =~ /N/ ) { my @v = split /\./, $st; die "I only have [0..$#letters] road names. You wanted the $v[0]th." if $v[0] > $#letters; return $letters[ $v[0] ] . "." . $v[1]; } elsif ( $direction =~ /E/ ) { return $st; } die "Shouldn't have got here."; }