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)

In reply to (jeffa) Re: reading files with DBD::CSV by jeffa
in thread reading files with DBD::CSV by data67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.