[Denver-pm] Text::CSV not parsing embedded commas?

Chris Fedde chris at fedde.us
Fri Jul 4 09:02:38 PDT 2014


#!perl

use Modern::Perl;
use Text::CSV;

$_=  q|file1,field2,field3,"more text, in this field 4",field5,field6|;

my $csv = Text::CSV->new();
$csv->parse($_);

say for $csv->fields;



On Wed, Jul 2, 2014 at 12:50 PM, Robert L. Harris <robert.l.harris at gmail.com
> wrote:

>
> So I found out WHY the idiot put the ' $_ =~ s/"//;' in the script.  I
> still get to beat him for doing it without telling us, but the 'why' is
> legitimate.
>
> Change the value of $_ to this:
>
> $_=  file1,field2,field3,"more text, in this field 4,field5,field6
>
> ( Field 4 generaly contains user input which is quoted, but it is
> truncated.  If the user input is > than that fiels will be missing the
> final closing quotes. )
>
> Now I have no idea how to compensate for that.
>
> Robert
>
>
>
>
>
>
>
> On Tue, Jul 1, 2014 at 12:26 PM, Robert L. Harris <
> robert.l.harris at gmail.com> wrote:
>
>>
>> Given this line:
>>
>> $_=  file1,field2,field3,"more text, in this field 4",field5,field6
>>
>> I would expect the output of ( $va1, $var2, $var3, $var4, $var5, $var6
>> )=$csv->fields(); to yield:
>>
>> $var1=field1
>> $var2=field2
>> $var3=field3
>> $var4="more text, in this field 4"
>> $var5=field5
>> $var6=field6
>>
>> Instead though I get
>>
>> $var1=field1
>> $var2=field2
>> $var3=field3
>> $var4="more text
>> $var5= in this field 4"
>> $var6=field5
>>
>> What am I missing?
>>
>> Robert
>>
>>
>>
>> --
>> :wq!
>>
>> ---------------------------------------------------------------------------
>> Robert L. Harris
>>
>> DISCLAIMER:
>>       These are MY OPINIONS             With Dreams To Be A King,
>>        ALONE.  I speak for                      First One Should Be A Man
>>        no-one else.                                     - Manowar
>>
>
>
>
> --
> :wq!
> ---------------------------------------------------------------------------
> Robert L. Harris
>
> DISCLAIMER:
>       These are MY OPINIONS             With Dreams To Be A King,
>        ALONE.  I speak for                      First One Should Be A Man
>        no-one else.                                     - Manowar
>
> _______________________________________________
> Denver-pm mailing list
> Denver-pm at pm.org
> http://mail.pm.org/mailman/listinfo/denver-pm
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/denver-pm/attachments/20140704/0713001e/attachment.html>


More information about the Denver-pm mailing list