
Kanji
User
/ Moderator
Jul 10, 2000, 1:35 PM
Post #2 of 2
(3104 views)
|
For real lookups you'd need zipcode / geocode mapping which isn't free, but a very simple script would be ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl -wT ## By Kanji T Bates <kanji@perlguru.com> use strict; use CGI qw(:standard); print header, start_html( -title => 'Store Locator' ); my @stores; if ( my $zip = param('zip') ) { if ( $zip =~ /^\d{5}$/ ) { while ( <DATA> ) { push @stores, [ (split /:/)[0..5] ] if /:$zip:/ && /:Y$/; } if ( @stores ) { print h2( "These stores are in/near $zip..." ); foreach my $store ( @stores ) { printf( "<hr><b>%s</b><br>%s<br>%s, %s %s<br>%s" => @$store ); } } else { print h2( "Sorry, there are no stores in/near $zip." ); } } else { print h2( "$zip isn't valid. Please re-enter a 5 digit zip." ); } print hr, "Search again? "; } print start_form, "Enter a 5 digit zip: ", textfield( -name => 'zip', -maxlength => 5 ), end_form, end_html; __DATA__ STORE:STREET:TOWN:STATE:ZIP:PHONE:NEAR-BY ZIPS:ACTIVE Buy From Us:5 Some St:Some Town:ST:05000:123-456-7890:05001:05002:05003:05012:Y Another Company:15 A St:Some Town:ST:05000:456-789-0123:05001:05002:05003:05012:N Buy From Them:10 Another St:Another Town:AT:43006:234-567-8901:43002:05001:Y</pre><HR></BLOCKQUOTE> [This message has been edited by Kanji (edited 07-10-2000).]
|