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
_ _ _ _
(_|| | |(_|><
_|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.