I also have this subroutine for calculating a distance: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 have two values which I will be using in the CalculateDistance subroutine: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; }
Example of data in my file which might help:CalculateDistance (54.988056, -1.619444, $Lat2, $Lon2);
I want to use the latitude and longitude from the file and implement it into the CalculateDistance subroutine.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
In reply to Re: (Beginner) Can 'qw' be implemented into a list?
by Halbird
in thread (Beginner) Can 'qw' be implemented into a list?
by Halbird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |