Indomitus has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to create a search engine for a CSV file of phone numbers. Each line in the CSV is a number, with the City, State and Area Code it's in. I can easily create a search for any of those fields individually or all of them if they're all filled in but I can't search for say, City and State with the Area Code field blank. If I fill in City and State, I want all the hits from the file that are a City with that name in the specified State, whatever Area Code it might be in. Or if I just fill in the Area Code, I want all numbers in that Area Code. I'd post code but I only have the basic split the line ,match the input to the value, if it matches push the line into an array for later printing.
I'm sure this is an easy problem, but for some reason I can't find the answer. I'm not opposed to using DBI but I figured there has to be an easier way. Thanks in advance.
Re: Search CSV for multiple parameters
by dreadpiratepeter (Priest) on Feb 13, 2002 at 19:30 UTC
|
I'd try DBD::CSV or such. Why code it yourself when a tested answer is already there. Besides, then when the project grows and the CSV becomes a dbtable you already have the code written.
-pete
Entropy is not what is used to be. | [reply] |
|
()-()
\"/
` | [reply] |
|
Send the following info and you shall have complete
script (free) within 24 hours by email:
1. Field Names 2. Type each field ( Text, Number, etc)
3. Search Fields to show on the html page
4. Search Fields that must be filled in the html
5. Display Fields
6. Validation of a field as either a number or email , in html pages,
if required
7. Order by which field.
satya@i91.net.in
| [reply] |
Re: Search CSV for multiple parameters
by zentara (Cardinal) on Feb 13, 2002 at 19:32 UTC
|
Want an easier way?, go to CPAN and get the Data-Table module.
http://search.cpan.org/search?dist=Data-Table | [reply] |
Re: Search CSV for multiple parameters
by tradez (Pilgrim) on Feb 13, 2002 at 22:24 UTC
|
At the end you say you are not opposed to using DBI. If you have a database, and the ability to use DBI, why the hell would you want to create a search engine from a CSV? That is ludacris, write a parse and a simple table structure and fill it in. Then setup a simple search engine script from the DB. Easiest and most efficient answer I can think of.
Tradez
"Never underestimate the predicability of stupidity"
- Bullet Tooth Tony, Snatch (2001) | [reply] |
|
The reason I'm using a CSV file is that's what I'm given by my vendor. I'd love to not have to deal with a CSV file and just use a database but as this is only for reading, not writing to, it seemed like overkill to get the new file, read the file in, parse it, write it to a database, then have to deal with DBI overhead just to read some phone numbers out of the file and display them on a webpage.
| [reply] |
|
But you can read from the vendor-delivered file *without* any changes through DBI with DBD::CSV.
| [reply] |
|