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

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.

Replies are listed 'Best First'.
Re^4: Load CSV file into Database
by tilly (Archbishop) on Feb 01, 2005 at 00:53 UTC
    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"; } }