in reply to CSV with embedded newlines
I'm pretty sure that Tie::CSV gets this wrong, unfortunately - I've tried to use it in the past, and never had much success. However, Text::CSV has worked for me with this type of file (well, Text::CSV_XS, which should be the same thing ;)
The basic loop structure that I have is something like:
my $csv = Text::CSV_XS->new({'binary' => 1}); my $current_line; while (<CVSFILE>) { $current_line .= $_; next unless ($csv->parse ($current)); my @row = $csv->fields(); $current = ''; # do stuff with the rows... }
This seemed to hold up against some really bizarre files (very _very_ big files, for example), so it looks pretty good. Strangely, I think Tie::CSV uses the Text::CSV module to read lines in, but I don't think it gets the loop right (like above). However, this might be my memory playing tricks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: CSV with embedded newlines
by doom (Deacon) on Apr 04, 2003 at 11:07 UTC |