http://qs1969.pair.com?node_id=1171336

keienn has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have a csv file with six columns as below;

NameA Longitude Latitude NameB Longitude Latitude
10001_NI0001, 36.79887354, -1.26122956, " WL3762", 34.52328889 , -1.007941667
NI0006, 36.86998613, -1.295393144, " NM5286", 36.83137418, -1.172626372
NI0066, 36.82748524, -1.25734101, " EC4140", 37.4580536, -0.53351668,

Am calling a subroutine 'distance' to calculate the distance between NameA and NameB. Here's where am stuck, how do I loop the first item on NameA column to iterate over all NameBs and return the smallest distance, together with both corresponding NameA and NameB entries then move to the next row and repeat above, and so on till end of file. I imagine a hash of arrays with NameA as keys will be appropriate to hold that result, but first i need to get over the loop part which i think is a nested for or foreach loop or such. Being new to Perl, I have not used the CSV module, wanted to try split first for better understanding. Below is a part of the relevant code and a sample of the output am getting;

open COMBINED, "<$outf" or die "couldn't open $outf\n"; while (<COMBINED>) { chomp $_; no warnings 'uninitialized'; @coords = (split /,/,$_); my $lat2G = $coords[2]; my $lon2G = $coords[1]; my $lat3G = $coords[5]; my $lon3G = $coords[4]; my $gsm_site = $coords[0]; my $umts_site = $coords[3]; #} my @coords2G = ($lat2G, $lon2G,); my @coords3G = ($lat3G, $lon3G,); foreach my $coord2G(@coords2G) { print $gsm_site,$umts_site,' ', distance(@coords2G, @coord +s3G, "K")."\n"; } }

The comma's are manually inserted for readability, not part of the output (which is tab I think)
NameA, NameB, 0
NameA, NameB, 0
10001_NI0001, WL3762, 254.534319729278
10001_NI0001, WL3762, 254.534319729278
NI0006, NM5286, 14.309312591142
NI0006, NM5286, 14.3093125911424