Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
As usual, investigating something relatively mundane yields some fascinating information. Any zip code database you come across in the next few months/years will probably be out of date -- zip codes are offically "mapped" by the census, and the Census Bureau hasn't completed last year's -- and it seems like the results of the survey are accurate to a county level.

The post office, naturally has their own interface which you can automate through LWP trickery. They indicate that the longest their data will rot is 2 months

If this is for big commercial use type work, maybe you wanna buy the TIGER/ZIP+4 database the USPS offer -- it cross-references ZIP code to geographic data.

The odd thing is that every database ( including the unfortunately named MAGGOT) warns that any data you get from any source is probably inaccurate to a (varying) degree.

Anyway, with the wide variety of possible ways to manipulate a ZIP code, here's one way to fulfill your original request :

#usr/bin/perl -w use strict; my $zip = "12345"; my @accepted = qw (12390 12351 12345 01241); foreach my $thiszip (@accepted){ print "Matched ", cmpZIP ($zip, $thiszip), "\n"; } sub cmpZIP { my ($zip_a,$zip_b) = @_; if ($zip_a eq $zip_b){return 5} my ($ichi, $ni, $san)=unpack ("a3aa",$zip_a); my ($ein, $zwei ,$drei)=unpack ("a3aa",$zip_b); if (($ichi eq $ein)&&($zwei eq $ni)) {return 4} if ($ichi eq $ein) {return 3} return 0; }
Although, after reading up on the subject, you may want to change this to a2a3 or a2aaa to reflect the state/county encoding in the ZIP.

In reply to (boo)Re: Algorythym for searching closest neighbor by boo_radley
in thread Algorythym for searching closest neighbor by belize

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found