At this point, I'm merely numerically comparing the user's zipcode to each one in the database and determining whether to return or discard each record. Is there a better way to do this?

Probably. This sounds like you are using a flat file 'data base' and simply iterating from the beginning of this to the end. For a small file this works fine but breaks down when you get bigger and or demand on access to this file becomes high. On way to arrange this in a proper database would be to have two tables:

Zip Table Zip Code,Distrubitor Code/s 71000, 1|2|3 72000, 3|4 .... Distributor Table Dist ID, Lotsa other Data :-) 1, She'll be right INC 2, No Worries Mate INC 3, Can Do Corp 4, The Impossible Done Yesterday P/L

You do the lookup on the Zip table (really basic SQL) to get the Dist ID(s) for that area (Pipe delimited here). You then grab all those Distributors from the Dist table. Presumbaly the Distributor ID table should already exist? So you just need to generate a Zip table that cross references the Zip code to the Dist ID. You could do this manually using a map or automate it using the zip code geographic position data mentioned elsewhere. You would probable need to get geographic co-ordinates for you distributors but this is pretty easy. You can get the longs and lats for any US city from many of the online mapping services free. See jcwren monk map page (on the stats pages) for one such link.

You could implement this using DBI and DBD::CSV making it easy to move to a real database in the future.

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Zipcode search engine by tachyon
in thread Zipcode search engine by Jerry

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.