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

In reply to Re: ZIP code distances by Cristoforo
in thread ZIP code distances by jrmtreebeard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.