Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Reading file into an array and working with it.

by chromatic (Archbishop)
on Jun 25, 2000 at 21:17 UTC ( [id://19759]=note: print w/replies, xml ) Need Help??


in reply to Reading file into an array and working with it.

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:

  1. Open the file.
  2. For each line, split it into $name and $location.
  3. Put the data into two hashes -- one in the format $name => $location, the other $location => $name.
  4. Close the file.
  5. Look up the location by name from the first hash.
  6. 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).
  7. 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.
  • Comment on Re: Reading file into an array and working with it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-26 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found