How do I find the number of animals within a certain distance of a certain point

27 views
Skip to first unread message

Yeorgia Argirou

unread,
Mar 25, 2015, 4:35:46 PM3/25/15
to unix-and-perl-...@googlegroups.com
I have a .txt file which contains 125,000 entries of sightings of mammals. Each line of the file has a species name, latitude and longitude (place of the sighting). I have to write a subroutine 'LocationCount' which returns the number of animals found within a specified distance of a given location. This should take four parameters: a file name containing the data, a distance in kilometres, and the latitude and longitude of the location. It should then return the number of animals found within the specified distance of the location. 

There are many other things I need to add in to this but I cannot get past the first step.

I first need to load the file into a list which I have successfully done. For every line in the list I then need to split the line into its three components: species name, latitude and longitude which I am struggling with. The fields are all separated by tabs. 

I have attached a print screen of my work, can anyone see where I am going wrong. I have tried many variations.
Perl.docx

Keith Bradnam

unread,
Mar 25, 2015, 4:42:21 PM3/25/15
to unix-and-perl-...@googlegroups.com
In your script you are using /t for a tab character when it should be \t (backslash). This may be why your split function is not working.

Keith Bradnam

unread,
Mar 25, 2015, 4:43:23 PM3/25/15
to unix-and-perl-...@googlegroups.com
P.S. You have some Perl code which is just plain text. It is overkill to attach a Word doc to show your code. Just paste the code into your discussion post and maybe change the font to Courier New.


On Wednesday, March 25, 2015 at 1:35:46 PM UTC-7, Yeorgia Argirou wrote:

Keith Bradnam

unread,
Mar 25, 2015, 4:47:49 PM3/25/15
to unix-and-perl-...@googlegroups.com
Other comments on your code:

  1. There are no comments!!! This doesn't make it easy for you (or for others) to follow what your code is trying to do
  2. There is a lot of code that simply won't work in your script. It really looks like you have tried adding a lot of code at once without testing it. Try to add the smallest amount of code possible before testing it. I.e. write code to open a file and print each line. Only if that works should you proceed any further
  3. I would possibly add many more comments, but there is no point unless you address the first two issues.

On Wednesday, March 25, 2015 at 1:35:46 PM UTC-7, Yeorgia Argirou wrote:
Reply all
Reply to author
Forward
0 new messages