Skip Menu |

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

Report information
The Basics
Id: 47464
Status: resolved
Priority: 0/
Queue: Text-CSV_XS

People
Owner: Nobody in particular
Requestors: perl [...] evancarroll.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.66



Subject: Quote of nulls
Is there anyway to pull in a null as an empty quote? "foo","","bar" as ['foo',undef,'bar']
Subject: Re: [rt.cpan.org #47464] Quote of nulls
Date: Tue, 30 Jun 2009 19:51:36 +0200
To: bug-Text-CSV_XS [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Tue, 30 Jun 2009 13:07:22 -0400, "Evan Carroll via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote: Show quoted text
> Is there anyway to pull in a null as an empty quote? > "foo","","bar" > > as ['foo',undef,'bar']
no, I don't think so /If/ it is possible, I'm sure it'll break other things. And how would you differentiate between empty and undef? even with a combination of allow_loose_quotes => 1, blank_is_undef => 1, echo '"foo","","bar"' | perl -MDP -MText::CSV_XS -we'my$csv=Text::CSV_XS->new({binary=>1,allow_loose_quotes=>1,blank_is_undef=>1});DDumper$csv->getline(*STDIN)' $VAR1 = [ 'foo', '', 'bar' ]; -- H.Merijn Brand http://tux.nl Perl Monger 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, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
On Tue Jun 30 13:51:56 2009, h.m.brand@xs4all.nl wrote: Show quoted text
> On Tue, 30 Jun 2009 13:07:22 -0400, "Evan Carroll via RT" > <bug-Text-CSV_XS@rt.cpan.org> wrote: >
> > Is there anyway to pull in a null as an empty quote? > > "foo","","bar" > > > > as ['foo',undef,'bar']
> > no, I don't think so > /If/ it is possible, I'm sure it'll break other things. > And how would you differentiate between empty and undef? > > even with a combination of > > allow_loose_quotes => 1, > blank_is_undef => 1, > > echo '"foo","","bar"' | perl -MDP -MText::CSV_XS >
-we'my$csv=Text::CSV_XS->new({binary=>1,allow_loose_quotes=>1,blank_is_undef=>1});DDumper$csv->getline(*STDIN)' Show quoted text
> $VAR1 = [ > 'foo', > '', > 'bar' > ]; >
Well it is ambiguous either way.. But, for perl, using the MooseX::Types I'd rather it be "undefined" than defined as an empty string (even though it is literally what it is, it is part of the CSV-exportation process). Actually, I can't think of any practical case where you would want to send an empty string in a csv file anyway, and not want the receiving end to correct it as NULL. Maybe something like this is called for: naked_quotes_are_undef => 1 Then I can say has 'price_term' => ( isa => 'Maybe[Int]', is => rw ); and do $self->price_term( value from $csv->fields )
Subject: Re: [rt.cpan.org #47464] Quote of nulls
Date: Tue, 30 Jun 2009 21:24:47 +0200
To: bug-Text-CSV_XS [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Tue, 30 Jun 2009 14:37:24 -0400, "Evan Carroll via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote: Show quoted text
> Well it is ambiguous either way.. But, for perl, using the MooseX::Types > I'd rather it be "undefined" than defined as an empty string (even > though it is literally what it is, it is part of the CSV-exportation > process). Actually, I can't think of any practical case where you would > want to send an empty string in a csv file anyway,
Oh, but I do, and use it day-in-day-out. When *exporting* databases to CSV, ,"", is an empty string, and ,, is a NULL value when using { quote_always => 1 } I see no other way to do that. Show quoted text
> and not want the receiving end to correct it as NULL. Maybe something > like this is called for: > > naked_quotes_are_undef => 1
in my perception that would be empty_is_undef => 1, but where is the reading function? How hard would it be to while (my $row = getline ($fh)) { my @row = @$row; to while (my $row = getline ($fh)) { my @row = map { $_ eq "" ? undef : $_ } @$row; Show quoted text
> Then I can say > has 'price_term' => ( isa => 'Maybe[Int]', is => rw ); > > and do $self->price_term (value from $csv->fields)
-- H.Merijn Brand http://tux.nl Perl Monger 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, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Show quoted text
> Oh, but I do, and use it day-in-day-out. When *exporting* databases to > CSV, ,"", is an empty string, and ,, is a NULL value when using > { quote_always => 1 } I see no other way to do that.
Well, I wasn't saying it was useless, I just said it was a poor default that can you can't override in the library. To each their own, though, this was just a wishlist item for me. I personally view an empty string, as a stringification of a NULL more likely than an verbatum empty field, simply because you can always not-know something, but only in select cases can you know something to be empty. Examples would include a practical application of a person's name. Show quoted text
> while (my $row = getline ($fh)) { > my @row = map { $_ eq "" ? undef : $_ } @$row;
This works so long as you only use functionality that retrieves the array-row and not the hashref-row.
Subject: Re: [rt.cpan.org #47464] Quote of nulls
Date: Wed, 1 Jul 2009 08:42:49 +0200
To: bug-Text-CSV_XS [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Tue, 30 Jun 2009 15:43:37 -0400, "Evan Carroll via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote: Show quoted text
> Queue: Text-CSV_XS > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=47464 > >
> > Oh, but I do, and use it day-in-day-out. When *exporting* databases to > > CSV, ,"", is an empty string, and ,, is a NULL value when using > > { quote_always => 1 } I see no other way to do that.
> > Well, I wasn't saying it was useless, I just said it was a poor default > that can you can't override in the library. To each their own, though, > this was just a wishlist item for me. I personally view an empty string, > as a stringification of a NULL more likely than an verbatum empty field, > simply because you can always not-know something, but only in select > cases can you know something to be empty.
And I didn't say it was unacceptable :) http://www.xs4all.nl/~hmbrand/Text-CSV_XS-0.66_01.tgz (that file will not stay there indefinitely) echo '"foo","","bar",' | perl -Iblib/lib -Iblib/arch -MDP -MText::CSV_XS -we'my$csv=Text::CSV_XS->new({binary=>1,empty_is_undef=>1});DDumper$csv->getline(*STDIN)' $VAR1 = [ 'foo', undef, 'bar', undef ]; Show quoted text
> Examples would include a practical application of a person's name. >
> > while (my $row = getline ($fh)) { > > my @row = map { $_ eq "" ? undef : $_ } @$row;
> > This works so long as you only use functionality that retrieves the > array-row and not the hashref-row.
$_ eq "" && ($_ = undef) for values %$hashref; -- H.Merijn Brand http://tux.nl Perl Monger 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, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/