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

database query matching

by Anonymous Monk
on Apr 26, 2000 at 07:03 UTC ( #9160=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm writing a program that takes user input from a form (3 inputs to be exact) and then compares against a database to come up with matching respones. i.e. a user enters 50 in the money input, carribean in the location and biking in the activity, and the program comes up with a list of resorts. How do I write this program, and how do I structure the flat text database. Coriolanus

Replies are listed 'Best First'.
RE: database query matching
by chromatic (Archbishop) on Apr 26, 2000 at 18:50 UTC
    It sounds like you just need one simple table, with four rows:
    Resort, Price, Location, and Activities

    Your SQL statements will be very simple, too -- similar to (SELECT * from resorts WHERE price <= ? AND activities LIKE ? AND LOCATION LIKE ?). Don't quote me on the exact syntax.

    I second the recommendation to use DBD::CSV and DBI. Not only will it allow you to use SQL syntax on a simple database (you can even edit it in most spreadsheets), it will let you write your program to the standard Perl database interface (DBI). In the future, if you want to get more complicated or put a real database behind it, you can do that with very little effort.

    Plus, it will give you good experience.

Re: database query matching
by plaid (Chaplain) on Apr 26, 2000 at 12:19 UTC
    In your particular situation, the best idea may be to use some sort of relational database (MySQL, mSQL, or any non-free ones if you can afford them...). At the best, you'd be re-inventing the wheel doing it yourself. In addition to structuring the flatfile database, you'd have to also do things such as index those 3 fields for fast lookups and efficient sorts.. Basically, doing things that the authors of databases have spent much time optimizing. If you are able to install software on the server, and/or can get someone to do it for you, MySQL is the best free way to go. If you are restricted to using flat-file databases, you'll probably want to do something like just a comma or tab delimited file, but a good amount of time will be spent making your searching methods efficient.
RE: database query matching
by ok (Beadle) on Apr 26, 2000 at 13:08 UTC
    Look into using DBI with DBD::CSV. You'll build character by learning a simple SQL select statement and realize how applicable and powerful and simple DBD::CSV is.
Re: database query matching
by frankus (Priest) on Apr 26, 2000 at 13:33 UTC
    For a ready made MySQL solution try this

    be warned though it can be a bit of a pig getting mysql, DBI, DBD, NET etc.

    I found little documentation, but the tutorial is good.

    ;-)

RE: database query matching
by t0mas (Priest) on Apr 26, 2000 at 11:34 UTC
    The best way is to use Ezdb located at www.ezperl.com and don't bother with how or look in the source if you still do ;-) /t0mas
RE: database query matching
by toadi (Chaplain) on Apr 26, 2000 at 13:29 UTC
    With a flat text-file you'll make it yourself very difficult
    Searchin in an non-indexed file is very intensive an with a longer text-file it will be a pain in the butt!!!
    For seaching make it a rule: indexed files only!!!
    Best option is get mysql/postgress and learn a bit of sql.
    With some easy statements you'll get much done

Re: database query matching
by egabriel (Initiate) on Apr 26, 2000 at 21:58 UTC
    Well, every resort will have a max price, a min price, one location, and many activities. So you can get away with three tables.
    resorts      resort_activities  activities<
    --------     ----------         ----------
    resort_id*   resort_id          activity_id
    name	     activity_id        description
    location
    
    This isn't too bad for a start. I personally recommend something like postgresql for this. DBD::CSV is good, but I don't know how it does with multi-table relations. You could really do all of this with one table instead of three, but your database wouldn't be 'normalized'. Look into the concept of 'normalization' before you design anything that needs to grow to any useful size.

    --Gabriel

Re: database query matching
by Anonymous Monk on Apr 26, 2000 at 11:01 UTC
    Hi,
    best is not to use a flat file for this
    Searching in a flat file is a bugger,the best thing to search is is in a indexed file

    of cource I don't know how big the flat text file will be
Re: database query matching
by Anonymous Monk on Apr 26, 2000 at 11:02 UTC
    Hi,
    best is not to use a flat file for this
    Searching in a flat file is a bugger,the best thing to search is is in a indexed file

    of cource I don't know how big the flat text file will be


Re: database query matching
by Anonymous Monk on Apr 26, 2000 at 15:10 UTC
    If you really want a simple flat-file database see Brent Michalski's Simple Perl Database at http://webreview.com/wr/pub/98/10/09/perl/index.html
RE: database query matching
by ok (Beadle) on Apr 28, 2000 at 22:30 UTC
    DBD::CSV can't do joins. Bummer.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2022-07-04 22:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?