Gossamer Forum
Home : General : Perl Programming :

zip code search

Quote Reply
zip code search
i am looking for information on a zip code searcher. say that there is a bunch of zip codes already in a database. someone enters in a zip code and then it goes throught the database and finds zip codes that are close to that one zip code. (i don't know if this is true or not, but i think that zip codes that are next to each other are just the nuext number up e.g. 90210 is close to 90211) is this even possible, how is this done on other sites? oh and based on teh zip code that you eneteren it displays a list of zip codes that are close to that zip code entered.

thanks for the info and help, just wondering if there is something like this already. or what steps i could go abut doing this.

Quote Reply
  In reply to
why is Gossamer Threads so slow today?

Quote Reply
Re: zip code search In reply to
its true.. zip codes go in order... zip codes on the east coast start at like 00001.. or something.. and they increase as they go west.. here in my city (near san francisco) its 95014..

anyways.. ummm.. i've done something like this once.. i remember it was for one of those Find the store closet to you things.. but i'm not exactly sure how i went about doing this..

the code can vary depending on where you get this list of zip codes.. i imagine you are going to get it from a database.. so it'll probably be in an array...

try something like this..

[@zipcodes defined earlier containing list of zip codes]

$code = 12345;

push (@zipcodes, $code);
@zipcodes = sort { $a <=> $b } @zipcodes;

for (my $i = 0; $i < @zipcodes; $i++) {
if ($zipcodes[$i] == $code) { $area = $i; last; }
}

@near = @zipcodes[$area - 3 .. $area - 1, $area + 1 .. $area + 3]; #!!!
@near = sort { $code - $a <=> $code - $b } @near; #!!!

$" = ", ";
print "@near\n";

umm.. a few lines on their i'm a bit shaky about.. i marked them with a "#!!!"

Jerry Su
widgetz sucks
Quote Reply
Re: zip code search In reply to
Thank you very much, that was exactly what i was looking for. that will definitelly help me. thank you again.