pglinx has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance...#!/usr/local/bin/perl5 #------------------ was php--------------------------- funtion distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($la +t1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } elsif ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } #--------------------------end was php------------------------ { $selectmiles = 30; $zipcood = "60.1843160, -128.5069940"; open(FILE, "area.txt") || die "I can't open that because: $!\n"; while(<FILE>) { chop; @all = split(/\n/); foreach $line (@all) { local($hStoreID, $hStoreName, $hStoreUserName, $hStorePassword, $h +StoreMCRSPassword, $hStoreCity, $hStoreProv, $hStoreAdd, $hStoreAdd2, + $hStorePC, $hStoreCountry, $hStoreEmail, $hStorePhone, $hStoreType, +$hStoreLatitude, $hStoreLongitude, $hStoreFirstName, $hStoreLastName, + $hStoreHPhone, $hStoreCPhone, $hStoreEmail2, hStoreOwner, hStoreAdmi +n, $hStoreAdmin2, $hStoreAdmin3, $hStoreActive, $hStoreWeb, $hStoreLa +ng, $hStoreDesc, $hStoreShowMap, $hStoreComingSoonText, $hStoreComing +SoonTextFrench, $hStoreVanityName, $hStoreWebCreatedDate, $hStoreLast +Login, $hStoreLastEnabled, $hStoreManagerEmpID, $hStoreURL) = split(/ + /, $line); distance($zipcood, $hStoreLatitude, $hStoreLongitude "M") if ("M" < "selectmiles") { $match = 1; $centerinfo = "$hStoreID, $hStoreName\n"; } } } close(FILE, "area.txt")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Zip code distance search
by kennethk (Abbot) on Mar 12, 2009 at 16:16 UTC | |
|
Re: Zip code distance search
by roboticus (Chancellor) on Mar 12, 2009 at 16:04 UTC | |
|
Re: Zip code distance search
by swampyankee (Parson) on Mar 12, 2009 at 18:11 UTC | |
|
Re: Zip code distance search
by toolic (Bishop) on Mar 12, 2009 at 16:15 UTC | |
|
Re: Zip code distance search
by scorpio17 (Canon) on Mar 12, 2009 at 16:14 UTC |