http://qs321.pair.com?node_id=1190195


in reply to Re^3: Multiple double quotes within csv
in thread Multiple double quotes within csv

Re the good Abbot NetWallah's observation that your code "doesn't compile" -- spot on and ++ even though his code could still encounter problems with slight variation in the non-conformity of the CSV (discussion below) -- here's why ...and how to fix compilation failure part of the problem:

#!/usr/bin/perl use strict; use warnings; # OP's code from question at #1190163 use Text::CSV; my $csv = Text::CSV->new({ sep_char => ',' }); while (my $line = <DATA>) { # added open curly if ($csv->parse($line)) { (my @fields) = $csv->fields(); # enclosed my @fields in () s +o $csv does not mask earlier print print "$fields[0],"; print "$fields[1],"; print "$fields[2]\n"; } else { warn "Line could not be parsed: $line\n"; } } __DATA__ 0,""Rat Control" <sip:+15559999999@192.168 .5.233>;tag=gK004bb052",9

If what you posted -- complete with strict and warnings -- that your attempt to run your code should have at least hinted at what was wrong. Adding use diagnostics (or perhaps use diagnostics -verbose or filtering your program thru splain would have at least allowed you to post code without errors... something the Monks hold to be an indicator that you're serious about learning rather than merely using us for human debuggers.

As to the underlying problems, attend carefully to Marshall's thorough examination and exposition ... and join him in thanks to Tux for the module.