Anytime you find yourself iterating through an array, looking for a specific value, you should stop and ask "Would a hash be better here?"
What I would do:
- Open the file.
- For each line, split it into $name and $location.
- Put the data into two hashes -- one in the format $name => $location, the other $location => $name.
- Close the file.
- Look up the location by name from the first hash.
- Write a couple of loops to cover the coordinates of the preefined area around the place (add to and subtract from the Lat/Lon values).
- Look up names (if they exist) by location in the second hash.
You might also look at the DBM file modules included with Perl, like
DB_File,
GDBM_File,
NDBM_File, and
ODBM_File. Also be aware that parsing many CSV files with a regex (even in a
split statement) is tricky, so
Text::CSV may come in handy.