note
ww
<p>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:</p>
<c>#!/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 () so $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</c>
<p>If what you posted -- complete with <c>strict</c> and <c>warnings</c> -- that your attempt to run your code should have at least hinted at what was wrong. Adding <c>use diagnostics</c> (or perhaps <c>use diagnostics -verbose</c> or filtering your program thru <c>splain</c> would have at least allowed you to <b>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.</b></p>
<p>As to the underlying problems, attend carefully to [Marshall]'s thorough examination and exposition ... and join him in thanks to [Tux] for the module.</p>
<div class="pmsig"><div class="pmsig-352046">
<br>
<p><center> [id://188642] </center></p>
<p><center>check Ln42!</center></p>
</div></div>
1190163
1190175