Prakash Prabhakar wrote:
I am using the following code in my .cgi progam (compiling with perl-5.8.6,
UNIX OS). It doesnt work. Could you please let me know what could be wrong?
I do not get any warnings/error messages/expected output. The .cgi and the
.csv are in the same directory.
My guess is that the line endings are not set explicitly (they default
to windows line endings). Try adding this :
$dbh->{'csv_tables'}->{'info'} = {
'file' => 'testtable.csv',
'eol' => "\n"
};
Be sure to use double quotes qround the \n. If that doesn't work try a
line ending specific to your OS (e.g. '\012' for *nix).
--
Jeff
Thanks,
Prakash
use warnings;
use DBI;
$dbh = DBI->connect("DBI:CSV:")
or die "Cannot connect: " . $DBI::errstr;
$dbh->{'csv_tables'}->{'info'} = { 'file' => *'testtable.csv'*};
$sth = $dbh->prepare("SELECT * FROM info")
or die "prepare: " . $dbh->errstr();;
$sth->execute()
or die "execute: " . $dbh->errstr();
while (my $row = $sth->fetchrow_hashref)
{
print("Found result row: id = ", $row->{'id'},", name = ",
$row->{'name'});
}
$sth->finish();
to work with *testtable.csv* file that contains just this:
name,id
DSA,123
I even modified the .csv file to have:
"name","id"
"DS",123