#! C:/ActivePerl/Perl/bin/perl # type of delimiter used in products delimited text file &parsepars; my $delimiter = "\t"; my $zipcode = ""; my $statecode = ""; my $citycode = ""; foreach $par (@pars) { @a=split(/=/,$par); $name=$a[0]; $value=$a[1]; $value=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value=~ s/~!/ ~!/g; $value=~ s/\+/ /g; if ($a[0] eq "zip"){ $zipcode = $value; } if ($a[0] eq "city"){ $citycode = uc $value; } if ($a[0] eq "state"){ $statecode = uc $value; } } print "Content-type: text/html Pragma: no-cache Zip Code Information Search This page demonstrates how to use perl to verify city, state, and zip code information.
The database that is used to get the zip code information was found on the web, and
I found that everyone wanted to charge lots of money to get this information. I have
been using it to verify shipping address on a web page and have found some missing
zip codes, but for the sake of being free, is not to shabby. I just thought others
may want this information without being charged by USPS or other businesses in the
business for selling zip code information.
City State Zip
"; $LOGFILE = "c:/zip_codes.txt"; open(LOGFILE) or die("Could not open log file."); foreach $line () { # chomp($line); # remove the newline from $line. # do line-by-line processing. #print $line; my ($zip,$lat,$long,$city,$state,$county,$type) = split($delimiter,$line,7); if ($zip eq $zipcode || $city eq $citycode || $state eq $statecode ){ my $html_row = qq^ ^; # display the code for the add to cart buttons for each product print $html_row; } } print "
Zip Code City State County Longitude Latitude Type
$zip $city $state $county $long $lat $type
"; ###################### MAPQUEST LINK FOR REFERENCE #http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=36.60350&longitude=-79.37622 ###################### sub parsepars { $input=""; if ($ENV{'REQUEST_METHOD'} eq "GET") { $input=$ENV{'QUERY_STRING'};} else { read(STDIN, $input, $ENV{'CONTENT_LENGTH'});} @pars=split(/&/, $input);}