in reply to Re^2: Multiple double quotes within csv
in thread Multiple double quotes within csv
Here is some Working code, and the output it produces:
#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new({ sep_char => ',', quote_char => undef , esc +ape_char=>undef }); while (my $line = <DATA>){ if ($csv->parse($line)) { my @fields = $csv->fields(); print "$fields[0],"; print "$fields[1],"; print "$fields[2]\n"; } else { warn "Line could not be parsed: '$line'\n"; my ($cde, $str, $pos, $rec, $fld) = $csv->error_diag (); print "DIAG:(CDE=$cde, STR=$str, POS=$pos, REC=$rec, FLD=$fld)\n +" } } __DATA__ 0,""Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9
The quotes at the start of Rat Control are problematic, and produce this error on default settings:>perl test2.pl 0,""Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9
...Disinformation is not as good as datinformation. Don't document the program; program the document.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Multiple double quotes within csv
by ww (Archbishop) on May 13, 2017 at 14:41 UTC | |
|
Re^4: Multiple double quotes within csv
by Anonymous Monk on May 13, 2017 at 07:22 UTC | |
by NetWallah (Canon) on May 13, 2017 at 18:17 UTC |