Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: (Beginner) Can 'qw' be implemented into a list?

by Halbird (Novice)
on Mar 24, 2015 at 23:53 UTC ( [id://1121236]=note: print w/replies, xml ) Need Help??


in reply to (Beginner) Can 'qw' be implemented into a list?

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.

Replies are listed 'Best First'.
Re^2: (Beginner) Can 'qw' be implemented into a list?
by GrandFather (Saint) on Mar 25, 2015 at 01:29 UTC

    How can you have code that looks like that, and use a phrase like "implement it into the CalculateDistance subroutine"? I guess you have found code somewhere that is doing almost what you want and you wish to bend it to fit? Something like:

    ++$count if CalculateDistance (54.988056, -1.619444, @data{@SList[ +1 .. 2]}) > $x;

    inside your while loop should be the trick.

    Perl is the programming world's equivalent of English

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1121236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found