in reply to Re^2: Multiple double quotes within csv
in thread Multiple double quotes within csv
So:
is malformed, incorrect CSV, this should be:2,""Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9
I made some experiments. Here are my (updated) results:2,"""Rat Control"" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9
I do not understand why Line 4 which starts with unnecessary quotes is not parsed? update: But could be that the double quotes must apply to the whole field and therefore the syntax in line 2 must be used.#!/usr/bin/perl use strict; use warnings; $|=1; ## turn off buffering for STDOUT use Text::CSV_XS qw( csv ); my $csv = Text::CSV_XS->new(); #using the defaults while (my $line = <DATA>) { if ($csv->parse($line)) { my @fields = $csv->fields(); print join ("|",@fields),"\n"; } else { warn "Line could not be parsed: $line\n"; } } =Prints: 1|Rat Control <sip:+15559999999@192.168 .5.233>;tag=gK004bb052|9 2|"Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052|9 3|Rat Control <sip:+15559999999@192.168 .5.233>;tag=gK004bb052|9 Line could not be parsed: 4,"Rat Control" <sip:+15559999999@192.168 .5 +.233>;tag=gK004bb052,9 5|123,456|abc 6|Rat|xyz 7|Rat Control|xyz Line could not be parsed: 8,""Rat Control" <sip:+15559999999@192.168 . +5.233>;tag=gK004bb052",9 =cut __DATA__ 1,Rat Control <sip:+15559999999@192.168 .5.233>;tag=gK004bb052,9 2,"""Rat Control"" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9 3,Rat Control <sip:+15559999999@192.168 .5.233>;tag=gK004bb052,9 4,"Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052,9 5,"123,456",abc 6,"Rat",xyz 7,"Rat Control",xyz 8,""Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9
|
|---|