Perhaps something like this (You need to provide the 'distance' sub):
use strict;
use warnings;
my (@gsm_site, @umts_site);
while (<DATA>) {
my ($name1,$lon1,$lat1, $name2,$lon2,$lat2) = split /[\s"]*,["\s]*/
+, $_;
next unless $lat1 and $lon1; # Avoid title lines
push @gsm_site, {NAME=>$name1, LAT=>$lat1, LON=>$lon1};
push @umts_site,{NAME=>$name2, LAT=>$lat2, LON=>$lon2};
}
for my $g (@gsm_site){
$g->{NEAREST} = $umts_site[0]; # Initial assumption til
+l we know better
$g->{DIST_TO_NEAREST} = distance($g->{LAT},$g->{LON}, $g->{NEARE
+ST}{LAT},$g->{NEAREST}{LON}, "K");
for my $u (@umts_site[1..$#umts_site]){
my $this_distance = distance($g->{LAT},$g->{LON}, $u->{LAT},$
+u->{LON}, "K");
next unless $this_distance < $g->{DIST_TO_NEAREST};
$g->{NEAREST} = $u;
$g->{DIST_TO_NEAREST} = $this_distance;
}
}
# Print them out
for my $g (@gsm_site){
print "$g->{NAME}, $g->{NEAREST}->{NAME}, $g->{DIST_TO_NEAREST},\n"
+;
}
__DATA__
NameA Longitude Latitude NameB Longitude Latitude
10001_NI0001, 36.79887354, -1.26122956, " WL3762", 34.52328889 , -1.00
+7941667
NI0006, 36.86998613, -1.295393144, " NM5286", 36.83137418, -1.17262637
+2
NI0066, 36.82748524, -1.25734101, " EC4140", 37.4580536, -0.53351668,
Note - you should really use a module like
Text::CSV, instead of the split hack, above.
...it is unhealthy to remain near things that are in the process of blowing up. man page for WARP, by Larry Wall
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.