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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.