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