in reply to Re: Load CSV file into Database
in thread Load CSV file into Database

Both your solution and the previous solution will silently omit lines with embedded returns. :-(

Replies are listed 'Best First'.
Re^3: Load CSV file into Database
by Aristotle (Chancellor) on Jan 31, 2005 at 10:12 UTC

    Yeah, that is a limitation of Text::CSV. I chose to stick with the OP's choice of module anyway, but of course I should have said something about that.

    Makeshifts last the longest.

      It is not an insurmountable limitation. All that you have to do is, every time the line doesn't parse, accumulate it into a buffer, and then prepend it to the next line. That will handle embedded returns.

      There is no reason that this piece of logic couldn't be built into Text::CSV. You could even name it getline to mirror what Text::CSV_XS does. But it isn't there so people tend to get this wrong.

      Incidentally here it is, (untested):

      sub Text::CSV::getline { my $self = shift; my $fh = shift; my $line = ""; my $line_no; while (<$fh>) { $line_no ||= $.; $line .= $_; return if $self->parse($line); } if ($line) { die "CSV parse error at line $line_no"; } }