Skip Menu |

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

Report information
The Basics
Id: 70021
Status: rejected
Priority: 0/
Queue: Text-xSV-Slurp

People
Owner: danboo [...] cpan.org
Requestors: njh [...] bandsman.co.uk
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.21
Fixed in: (no value)



Subject: Fails to import if a field contains a hyperlink
The following program only prints n1 and n2. It stops importing at n3: #!/usr/bin/perl -w use Text::xSV::Slurp; my @l = ( 'name!comments', 'n1!c1;', 'n2!c2', 'n3!c3 <a href="www.example.com">click here</a>', 'n4!c4', ); my $t = xsv_slurp( shape => 'aoh', text_csv => {sep_char => '!' }, string => join("\n", @l), ); my @l2 = @{$t}; foreach (@l2) { print "$_->{name}\n"; }
From: njh [...] bandsman.co.uk
I've done some more research, it's not the hyperlink that is confusing the software, it's the quote. Text::xSV::slurp can't cope with this either :-( #!/usr/bin/perl -w use Text::xSV::Slurp; my @l = ( 'name!comments', 'n1!c1;', 'n2!c2', 'n3!c3"', 'n4!c4', ); my $t = xsv_slurp( shape => 'aoh', text_csv => {sep_char => '!' }, string => join("\n", @l), ); my @l2 = @{$t}; foreach (@l2) { print "$_->{name}\n"; }
This is likely an issue with your Text::CSV_XS constructor options. I suggest looking at the options related to quote characters. I'll look at why this isn't being escalated to an error when parsing. Thanks!
From: njh [...] bandsman.co.uk
Thanks for your reply and the pointer. Since I know I don't need quoting I change the code. It still doesn't work, but in a different way: nigel:~ nigel$ cat foo #!/usr/bin/perl -w use Text::xSV::Slurp; my @l = ( 'name!comments', 'n1!c1;', 'n2!c2', 'n3!c3 ""', 'n4!c4', ); my $t = xsv_slurp( shape => 'aoh', text_csv => { sep_char => '!' }, string => join("\n", @l), text_csv => { quote_char => undef }, ); my @l2 = @{$t}; foreach (@l2) { print "$_->{name}, $_->{comments}\n"; } nigel:~ nigel$ ./foo Use of uninitialized value in concatenation (.) or string at ./foo line 24. Use of uninitialized value in concatenation (.) or string at ./foo line 24. , Use of uninitialized value in concatenation (.) or string at ./foo line 24. Use of uninitialized value in concatenation (.) or string at ./foo line 24. , Use of uninitialized value in concatenation (.) or string at ./foo line 24. Use of uninitialized value in concatenation (.) or string at ./foo line 24. , Use of uninitialized value in concatenation (.) or string at ./foo line 24. Use of uninitialized value in concatenation (.) or string at ./foo line 24. , nigel:~ nigel$
On Thu Aug 04 15:08:42 2011, njh@bandsman.co.uk wrote: Show quoted text
> > my $t = xsv_slurp( > shape => 'aoh', > text_csv => { sep_char => '!' }, > string => join("\n", @l), > text_csv => { quote_char => undef }, > );
You need to combine your two 'text_csv' parameters like so: text_csv => { sep_char => '!', quote_char => undef }, Otherwise you are losing 'sep_char' setting.
From: njh [...] bandsman.co.uk
D'oh. Of course. Thanks for pointing it out. It's certainly much closer now - I just need to get it to import the quote characters. I've turned quoting off, but it still treats it as a special character. I can get around it by having ""foo"", but I shouldn't need to do that since I've turned off the functionality. nigel:~ nigel$ cat foo #!/usr/bin/perl -w use Text::xSV::Slurp; my @l = ( 'name!comments', 'n1!c1;', 'n2!c2', 'n3!c3 "foo"', 'n4!c4', ); my $t = xsv_slurp( shape => 'aoh', text_csv => { sep_char => '!', quote_char => undef }, string => join("\n", @l), ); my @l2 = @{$t}; foreach (@l2) { print "$_->{name}, $_->{comments}\n"; } nigel:~ nigel$ ./foo n1, c1; n2, c2 n3, c3 foo n4
I believe you need: { sep_char = '!', allow_loose_quotes => 1 }
From: njh [...] bandsman.co.uk
Excellent thanks!
Not a bug. Just needed the right Text::CSV_XS constructor options.