CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Text::CSV_XS->new with binary=1 problem


New User

Feb 8, 2007, 8:28 AM

Post #1 of 1 (353 views)
Text::CSV_XS->new with binary=1 problem Can't Post

I have a csv file in which some fields contain line feeds (or new lines, not sure). These fields are delimited by (")

When I process it I set up "binary" to 1 but the lines that contain this kind of fields come back wrong. The line feed is not read as part of the field but as a true row separator. As a consequence the resulting first row has the last field starting with a (") that lacks its closing pair and the 2nd one has its first field with closing (") but no opening. Both those lines are ignored and come out as empty. See attachments.

What am I doing wrong?

Thanks a lot

My code:

my $parser=Text::CSV_XS->new({
'quote_char' => '"',
'escape_char' => '"',
'sep_char' => ',',
'binary' => 1

open CSV, "$csv_path_n_file";

for $line (<CSV>){
my $status = $parser->parse($line);
my @columns = $parser->fields();
print "$_|" for @columns;
print "\n----------- sep -----------\n";

close CSV;
Attachments: csv source file.bmp (25.7 KB)
  output.bmp (29.6 KB)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives