You are connecting twice - remove the second one and change the first to:
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:my $dbh = DBI->connect( "DBI:CSV:f_dir=/export/home/devtools;csv_eol=\n;csv_sep_char=!;", {RaiseError=>1}, );
to simply this:$sth->execute() or die "Cannot execute: " . $sth->errstr();
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:$sth->execute();
is a MRWTDI (more robust way to do it).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, };
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)
In reply to (jeffa) Re: reading files with DBD::CSV
by jeffa
in thread reading files with DBD::CSV
by data67
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |