in reply to reading files with DBD::CSV

That was a hard bug to find! ;)

You are connecting twice - remove the second one and change the first to:

my $dbh = DBI->connect( "DBI:CSV:f_dir=/export/home/devtools;csv_eol=\n;csv_sep_char=!;", {RaiseError=>1}, );
The important part is setting csv_eol to a newline. The RaiseError part is not necessary, but it prevents you from having to check each and every DB transaction - so you can change this:
$sth->execute() or die "Cannot execute: " . $sth->errstr();
to simply this:
$sth->execute();
And thanks, because your code showed me how to use a csv file with a 'dot extension' (that is, "foo.csv"). I was under the impression that you could not do that. Oh, and:
use strict; # please ;) use DBI; use File::Basename; my $dir = '.'; my $file = 'simple.csv'; my $table = (fileparse($file,'.csv'))[0]; my $cols = [qw(foo bar baz)]; my $sep = ':'; my $dbh = DBI->connect( "DBI:CSV:f_dir=$dir;csv_eol=\n;csv_sep_char=$sep;", {RaiseError=>1}, ); $dbh->{csv_tables}->{$table} = { file => $file, col_names => $cols, };
is a MRWTDI (more robust way to do it).

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: reading files with DBD::CSV
by data67 (Monk) on Jun 14, 2002 at 16:09 UTC
    You are most welcome!
    By the way, with DBD::CSV you can work with flat-file databases as if they were real tables. So this means that you can use the power/ease of SQL in these. The eception here is that that one of the limitations of DBD::CSV is that it does not allow table "joins" and therefore sub-queries can be used.

    And yes, you were right. I was connecting twice to the file!!

    Thanks