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

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

People
Owner:
HMBRAND [...] cpan.org
Requestors:
melazyboy [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
Normal
Broken in:
0.51
Fixed in:
0.52



Subject: getline_hr produces a warning if any column_name is undef
One of the .xls feeds I have openoffice exports with a header row of ,"ST",,"SERIAL #","YR","MAKE","Model","WB","GVW","BRAKE" It turns out the that if any column header is undef, the first one included you will get the following error: Use of uninitialized value in hash slice at /usr/local/lib/perl5/site_perl/5.10.0/x86_64-linux/Text/CSV_XS.pm line 445, <GEN0> line 287.
On Thu, 19 Jun 2008 23:19:41 +0200, Gintas Grigelionis <g.grigelionis@computer.org> wrote:
Show quoted text
> H.Merijn Brand wrote:
> > On Tue, 17 Jun 2008 23:43:03 +0200, g.grigelionis@computer.org
wrote:
Show quoted text
> > > > Thanks for the report, but I cannot reproduce this. I've tried with > > 5.8.0 with and without UTF-8 locales, but I cannot make it fail. > > I do not have a threaded 5.8.0 version at hand, but would like to
see
Show quoted text
> > what failed why.
> > This has to do with broken UTF-8, setting LANG=C makes tests pass. > Unfortunately, I cannot make tests more verbose.
5.8.0 is not the most UTF-8 safe version of perl. Try to upgrade to 5.8.4 or up. 5.8.8 is current, and 5.8.9 is about to be released in not too long from now.
Subject: Re: [rt.cpan.org #36839] getline_hr produces a warning if any column_name is undef
Date: Thu, 19 Jun 2008 08:18:49 +0200
To: bug-Text-CSV_XS@rt.cpan.org
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
On Wed, 18 Jun 2008 17:41:06 -0400, "Evan Carroll via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote:
Show quoted text
> One of the .xls feeds I have openoffice exports with a header row of > ,"ST",,"SERIAL #","YR","MAKE","Model","WB","GVW","BRAKE" > > It turns out the that if any column header is undef, the first one > included you will get the following error:
This very much depends on the way you called the constructor. Is it possible to get the script and the file>
Show quoted text
> Use of uninitialized value in hash slice at > /usr/local/lib/perl5/site_perl/5.10.0/x86_64-linux/Text/CSV_XS.pm line > 445, <GEN0> line 287.
-- H.Merijn Brand Amsterdam Perl Mongers (http://amsterdam.pm.org/) using & porting perl 5.6.2, 5.8.x, 5.10.x on HP-UX 10.20, 11.00, 11.11, & 11.23, SuSE 10.1 & 10.2, AIX 5.2, and Cygwin. http://qa.perl.org http://mirrors.develooper.com/hpux/ http://www.test-smoke.org http://www.goldmark.org/jeff/stupid-disclaimers/
From: melazyboy@gmail.com
I'm still not sure exactly what the bug is but this report I did was way deceiving. I was remiss in debugging this. The bug is related to blank_is_undef. I have attached a test. Shout if you need anything else for me
use Text::CSV_XS; use IO::Handle; use Test::More tests => 1; our $failed = 0; $SIG{ '__WARN__' } = sub { print @_; $failed++ }; eval { my $csv = Text::CSV_XS->new({ blank_is_undef => 1 }); my $header_row = $csv->getline(\*DATA); $csv->column_names( $header_row ); 1 while ( my $tuple = $csv->getline_hr(\*DATA) ); }; ok ( !$failed, 'We did not fail the blank_is_undef test' ); 1; __DATA__ ,"ST","UNIT #","SERIAL #","YR","MAKE","Model","WB","GVW","BRAKE","ENGINE","JAKE","EXH","Air Cl","TRANSMISSION","Axle's","Tanks","SUSP","TIRES & WHEELS","COLOR","BODY","Doors","LIFT G","Reefer Make","Reefer/HRS","Miles","PRICE", "Atlanta","GA",40409,"1FDXE45P56DB40409",2006,"FORD","E-450",176,14050,"Hyd","6.0L Diesel","NO",,,"Elec 5- spd Auto",,,"Spr","LT225/75R16","White","16' service body",,,,,16000,28000,
Subject: Re: [rt.cpan.org #36839] getline_hr produces a warning if any column_name is undef
Date: Sat, 28 Jun 2008 00:47:07 +0200
To: bug-Text-CSV_XS@rt.cpan.org
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
On Fri, 27 Jun 2008 17:48:05 -0400, "Evan Carroll via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote:
Show quoted text
> Queue: Text-CSV_XS > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=36839 > > > I'm still not sure exactly what the bug is but this report I did was way > deceiving. I was remiss in debugging this. The bug is related to > blank_is_undef. I have attached a test. > > Shout if you need anything else for me
Several things here. The hashref is bound to fail here for multiple reasons. It was set up because it was requested, but it actually is quite accident prone. What if there is more than one single fields with the same `name' in the header? Or if there are more fields in the header line that result to the same (empty) name? It was not my intention to make that work. But I agree that the current way isn't to most user friendly. Try this. --8<--- diff --git a/CSV_XS.pm b/CSV_XS.pm index b622344..1af85ba 100644 --- a/CSV_XS.pm +++ b/CSV_XS.pm @@ -30,7 +30,7 @@ use DynaLoader (); use Carp; use vars qw( $VERSION @ISA ); -$VERSION = "0.51"; +$VERSION = "0.52"; @ISA = qw( DynaLoader ); sub PV { 0 } @@ -423,7 +423,7 @@ sub column_names $self->{_is_bound} && @keys != $self->{_is_bound} and croak ($self->SetDiag (3003)); - $self->{_COLUMN_NAMES} = [ @keys ]; + $self->{_COLUMN_NAMES} = [ map { defined $_ ? $_ : "UNDEF" } @keys ]; @keys; } # column_names @@ -445,7 +445,7 @@ sub bind_columns $self->_set_attr_N ("_is_bound", scalar @refs); $self->{_BOUND_COLUMNS} = [ @refs ]; @refs; - } # column_names + } # bind_columns sub getline_hr { @@ -1250,14 +1250,12 @@ internal failure, like failing to store a hash value. =item More Errors & Warnings -At current, it is hard to tell where or why an error occured (if -at all). New extensions ought to be clear and concise in reporting -what error occurred where and why, and possibly also tell a remedy -to the problem. error_diag is a (very) good start, but there is more -work to be done here. +New extensions ought to be clear and concise in reporting what error +occurred where and why, and possibly also tell a remedy to the problem. +error_diag is a (very) good start, but there is more work to be done here. -Basic calls should croak or warn on illegal parameters. Errors -should be documented. +Basic calls should croak or warn on illegal parameters. Errors should be +documented. =item eol diff --git a/ChangeLog b/ChangeLog index 3a65deb..f874bea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-06-28 0.52 - H.Merijn Brand <h.m.brand@xs4all.nl> + + * Using undef for hash keys is a bad plan + 2008-06-17 0.51 - H.Merijn Brand <h.m.brand@xs4all.nl> * Allow UTF8 even without binary => 1 -->8--- -- H.Merijn Brand Amsterdam Perl Mongers http://amsterdam.pm.org/ using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00, 11.11, 11.23, and 11.31, SuSE 10.1, 10.2, and 10.3, AIX 5.2, and Cygwin. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Subject: Re: [rt.cpan.org #36839] getline_hr produces a warning if any column_name is undef
Date: Sat, 28 Jun 2008 15:56:15 +0200
To: bug-Text-CSV_XS@rt.cpan.org
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
On Fri, 27 Jun 2008 17:48:05 -0400, "Evan Carroll via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote:
Show quoted text
> Queue: Text-CSV_XS > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=36839 > > > I'm still not sure exactly what the bug is but this report I did was way > deceiving. I was remiss in debugging this. The bug is related to > blank_is_undef. I have attached a test. > > Shout if you need anything else for me
Just uploaded 0.52, which should have fixed this. Documentation has been updated to reflect the changes. -- H.Merijn Brand Amsterdam Perl Mongers http://amsterdam.pm.org/ using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00, 11.11, 11.23, and 11.31, SuSE 10.1, 10.2, and 10.3, AIX 5.2, and Cygwin. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/


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.