Sorry. Let me be more clear about this:
I have this code which splits a data file into headings (Im sure some of this is redundant for what I want to do):
my @SList = qw(Name Latitude Longitude);
my $FileA = "Mammal.txt";
open my $Mammals, "<", $FileA or die "Cannot open file'$FileA'.";
while (my $line = <$Mammals>) {
my %data;
@data{@SList} = split /\t/, $line, scalar @SList;
foreach my $species (@SList) {
printf "%-10.10s : %s\n", $species, $data{$species};
}
}
close $Mammals;
I also have this subroutine for calculating a distance:
sub CalculateDistance($$$$)
{
my ($Lat1, $Lon1, $Lat2, $Lon2) = @_;
my ($nDLat, $nDLon);
my ($nA, $nC, $nD);
$nDLat = ($Lat1 - $Lat2) * 0.017453293;
$nDLon = ($Lon1 - $Lon2) * 0.017453293;
$Lat1 = ($Lat1) * 0.017453293;
$Lat2 = ($Lat2) * 0.017453293;
$nA = (sin($nDLat/2) ** 2) + cos($Lat1) * cos($Lat2) * ( sin($nDLon/2
+) ** 2 );
$nC = 2 * atan2( sqrt($nA), sqrt( 1 - $nA ));
$nD = 6372.797 * $nC;
return $nD;
}
I have two values which I will be using in the CalculateDistance subroutine:
CalculateDistance (54.988056, -1.619444, $Lat2, $Lon2);
Example of data in my file which might help:
Myotis daubentonii 52.12909504 -0.882318328
Myotis nattereri 53.90074722 -1.771685946
Myotis nattereri 54.08052026 -1.770700447
Myotis nattereri 53.54023273 -1.471802022
Eptesicus serotinus 51.40241395 0.250171498
Eptesicus serotinus 51.35533502 0.242835438
Eptesicus serotinus 51.0001581 0.351815969
I want to use the latitude and longitude from the file and implement it into the CalculateDistance subroutine.
Then I can create a counter which calculates how many data sets return a distance of more than x.
Does this make any more sense? I appreciate everyone's advice, and although I read through all of your examples I think I explained myself so terribly that my question was misunderstood.