This queue is for tickets about the Text-CSV_XS CPAN distribution.

Report information
The Basics
Id:
81526
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
RSAVAGE [...] cpan.org
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: getline_hr_all dies silently when input field uses double-quotes
Hi Here is my output from running the attached 'text.csv.pl': ron@zigzag:~$ perl text.csv.pl Writing: Input: <1One1>. Output: <1One1> Input: <2"Two"2>. Output: <"2""Two""2"> Input: <3Three3>. Output: <3Three3> Reading: Line => 1One1. ron@zigzag:~$ The " embedded and doubled in line 2 causes getline_hr_all to die silently, so what the module writes can't be read. Cheers Ron
Subject: text.csv.pl
#!/usr/bin/env perl use strict; use warnings; use IO::File; use Text::CSV_XS; use Try::Tiny; # ----------------------------------------------- sub read_csv_file { my($file_name) = @_; my($csv) = Text::CSV_XS -> new; my($io) = IO::File -> new($file_name, 'r'); my($result); try { $csv -> column_names($csv -> getline($io) ); $result = $csv -> getline_hr_all($io); } catch { die qq|Error: $_. err_diag: | . $csv -> err_diag; }; return $result; } # End of read_csv_file. # ----------------------------------------------- sub write_csv_file { my($file_name, $data) = @_; my($csv) = Text::CSV_XS -> new; open(OUT, '>', $file_name) || die "Can't open(> $file_name): $!"; my($line); my($status); $status = $csv -> combine('Line') || die "Can't combine('Line'): " . $csv -> err_diag; print OUT $csv -> string, "\n"; for my $row (@$data) { $status = $csv -> combine($row) || die "Can't combine($row): " . $csv -> err_diag; $line = $csv -> string; print OUT "$line. \n"; print "Input: <$row>. Output: <$line>\n"; } close OUT; } # End of write_csv_file. # ----------------------------------------------- my($data) = ['1One1', '2"Two"2', '3Three3']; my($file_name) = 'x.csv'; print "Writing: \n"; write_csv_file($file_name, $data); print "Reading: \n"; my($result) = read_csv_file($file_name); for my $row (@$result) { print join(', ', map{qq|$_ => $$row{$_}|} sort keys %$row), "\n"; }
On Thu Nov 29 00:41:02 2012, RSAVAGE wrote:
Show quoted text
> Hi > > Here is my output from running the attached 'text.csv.pl': > > ron@zigzag:~$ perl text.csv.pl > Writing: > Input: <1One1>. Output: <1One1> > Input: <2"Two"2>. Output: <"2""Two""2"> > Input: <3Three3>. Output: <3Three3> > Reading: > Line => 1One1. > ron@zigzag:~$ > > The " embedded and doubled in line 2 causes getline_hr_all to die > silently, so what the module writes can't be read.
Change line 158 from: print OUT "$line. \n"; to: print OUT "$line\n"; and it reads the file successfully. Adding code like that from the SYNOPSIS: $csv->eof or print $csv->error_diag; to your original code you'll see a 2023 parse error, due to the "." (rather than a separator or NL) outside the quotes. Tony
As by Tony's fine analysis: not a bug
Subject: Re: [rt.cpan.org #81526] getline_hr_all dies silently when input field uses double-quotes
Date: Wed, 05 Dec 2012 08:30:14 +1100
To: bug-Text-CSV_XS@rt.cpan.org
From: Ron Savage <ron@savage.net.au>
Hi Agggghhhh. Yes. My fault entirely. Sorry for the noise. On 04/12/12 19:34, TONYC via RT wrote:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=81526> > > On Thu Nov 29 00:41:02 2012, RSAVAGE wrote:
>> Hi >> >> Here is my output from running the attached 'text.csv.pl': >> >> ron@zigzag:~$ perl text.csv.pl >> Writing: >> Input:<1One1>. Output:<1One1> >> Input:<2"Two"2>. Output:<"2""Two""2"> >> Input:<3Three3>. Output:<3Three3> >> Reading: >> Line => 1One1. >> ron@zigzag:~$ >> >> The " embedded and doubled in line 2 causes getline_hr_all to die >> silently, so what the module writes can't be read.
> > Change line 158 from: > > print OUT "$line. \n"; > > to: > > print OUT "$line\n"; > > and it reads the file successfully. > > Adding code like that from the SYNOPSIS: > > $csv->eof or print $csv->error_diag; > > to your original code you'll see a 2023 parse error, due to the "." > (rather than a separator or NL) outside the quotes. > > Tony >
-- Ron Savage http://savage.net.au/ Ph: 0421 920 622


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.