in reply to OK, OK, I'm taking the DBI plunge. Now what?

When you send a request to the DBI ($sth->execute()), you should collect your data, before using $sth->finish().
Something like the (untested)
$dbh = DBI->connect(qq{DBI:CSV:csv_sep_char=\\|}, {RaiseError => 1} ); # here goes the $sth->prepare .... $sth->execute(); while (my @result = $sth->fetchrow_array()) { print $result[0], ", " # first field $result[1], ", " # second field and so on "\n" } $sth->finish(); $dbh->disconnect();
Repeat the above proceedings, changing the query, to get the lists that you need.
I didn't follow the amusement that you are referring to, but I can see that you are trying to solve a problem without appropriate tools.

Please, allow me to give you some friendly advice:
1 If you ask for help, try to give some information about what you want to achieve. From the little you are saying, we see that you want to use the DBI to query text files. Everyone with some experience of database will tell you that this is not a sound idea. You don't leave us a choice. You present the problem whose only solution is to munge a text file, thus preventing some volunteer from pointing to some alternative path.
2 Using a tool like the DBI makes sense if you want to store data in a database and then retrieve it. Putting it up only for querying a CSV file could be seen as overkill. Again this is a result of not knowing enough about your problem.
3 If you don't have to store the information somewhere else, just parse the text file with split or using Text::xSV (see tilly's node and the module itself for more info) and use the resulting lists.
4 If you really must use the DBI, try to organize your application to have the data supplied in a more sensible way. If you have no choice but to use this file format, try to make it just temporary, and use a real database for storing data.

How can I make a list from multiple field choices?
SQL accepts multiple clauses in the WHERE statement (eg: WHERE field_1 = "Yes" and field_3 IS NULL). But check the documentation of the DBD driver you are using to see that this syntax is accepted. Some drivers don't allow the IS NULL clause, but want Field_3 = "" instead.
There is little more I can tell you, without info about what you really want to achieve. If you don't need to store data in a database, and especially if you are not confortable with SQL, you should rely on some paradigm that you know better.
Cheers
 _  _ _  _  
(_|| | |(_|><
 _|   

Replies are listed 'Best First'.
Re: Re: OK, OK, I'm taking the DBI plunge. Now what?
by peppiv (Curate) on Jan 11, 2002 at 01:06 UTC
    Thanks gmax for the advice. I do plan on putting this into a real database sometime soon. I thought that since it already was in a text file, I'd learn to DBI query it first as the transition to converting and querying a real database might be a bit too much to handle in one fell swoop.

    I know I don't always put enough info in my questions. I try to be courteous and keep it short and simple.

    thanks for the replies
    peppiv
    if time is money....is it safe to say it's five dollars past three hundred?
      Putting this into a database should be trivial once you are ready to do so. bcp is your friend (use "|" as your field terminator and "\n" as your row terminator and you're golden)
        And pray none of your data has returns or pipes.

        That is a pretty big assumption. Big assumptions like that are what leads to fragile infrastructures. Defensive programmers try to avoid that kind of fragility if at all possible...