in reply to ZIP code distances

I forget where I got my zip code file, but a search should find you a downloadable one. I used the Geo::Ellipsoid module. I was really only playing around so I can't say the code does much but maybe it will give you an idea. The program figures the distance between 2 zip codes

Chris

Update (major): I posted a bad binary search sub. :-(
Eliminated the code. I thought it was ok but when I tested it against every zip code in the file, about 1/4 came back as unfound.

Update2: As long as the file is read into memory anyhow, could have used a hash (no need for a binary search).

#!/usr/bin/perl use strict; use warnings; use Geo::Ellipsoid; open IN, "zip_codes.csv" or die $!; my @codes = <IN>; close IN or die $!; my ($zip1, $zip2) = @ARGV; my @zip1 = split /,/, $codes[ number_bin_search($zip1, \@codes) ]; my @zip2 = split /,/, $codes[ number_bin_search($zip2, \@codes) ]; my $geo = Geo::Ellipsoid->new(units=>'degrees'); my $d = .000621 * $geo->range(@zip1[1,2], @zip2[1,2]); print "MILES: $d - @zip1[3,4] - @zip2[3,4]\n"; __END__ (small contents of 42,741 codes in zip_codes.csv) 43787,+39.548994,-081.826194,STOCKPORT,OH,MORGAN,STANDARD 43788,+39.795107,-081.370927,SUMMERFIELD,OH,NOBLE,STANDARD 43789,+39.654386,-081.240732,SYCAMORE VALLEY,OH,MONROE,PO BOX ONLY 43791,+39.871330,-082.098668,WHITE COTTAGE,OH,MUSKINGUM,PO BOX ONLY 43793,+39.751516,-081.075921,WOODSFIELD,OH,MONROE,STANDARD 43802,+40.090767,-081.855203,ADAMSVILLE,OH,MUSKINGUM,STANDARD 43803,+40.357237,-081.643638,BAKERSVILLE,OH,COSHOCTON,PO BOX ONLY 43804,+40.426559,-081.674440,BALTIC,OH,TUSCARAWAS,STANDARD 43805,+40.398274,-081.968787,BLISSFIELD,OH,COSHOCTON,PO BOX ONLY 43811,+40.247685,-081.929225,CONESVILLE,OH,COSHOCTON,STANDARD 43812,+40.300934,-081.864066,COSHOCTON,OH,COSHOCTON,STANDARD 43821,+40.106916,-081.999822,DRESDEN,OH,MUSKINGUM,STANDARD 43822,+40.108668,-082.103212,FRAZEYSBURG,OH,MUSKINGUM,STANDARD 43824,+40.364667,-081.755507,FRESNO,OH,COSHOCTON,STANDARD 43828,+40.351271,-081.873607,KEENE,OH,COSHOCTON,PO BOX ONLY 43830,+40.063883,-082.099574,NASHPORT,OH,MUSKINGUM,STANDARD