http://qs1969.pair.com?node_id=694543


in reply to dump text file in ASCII and hex

kevind0718

Text::CSV_PP manual is your friend. It mentions a method that can be helpful :

$csv->error_diag()
When I added a call and a print like this
$status = $csv->parse($line); printf "status=%d\n", $status; unless ($status) { printf "error=%d %s\n", ( $csv->error_diag()); } @col = $csv->fields(); print Dumper \@col;
I obtained this printout for your first test line :
"fred1234","bedrock quary","S","t","88579Y101","4851","2595708","US885 +79Y1010","MMM","3M CO","USD","USD","SB7",1,19610718,19610718,225212," +MMM UN","MMM.N","",1,"C",710.964086349999,710.964086349999,710.964086 +35,,,2.45938,,,,"R" ~~ status=0 error=2027 EIQ - Quoted field not terminated $VAR1 = [ undef ]; --new line--
You will notice that there is a space after the last doublequote character, and this is what the parser does not like.

Below, I added a kludge that makes the problem go away.

#! perl -w use strict; use Text::CSV_PP; use Data::Dumper; $csv = Text::CSV_PP->new(); # create a new CSV parser object while (defined($line = <> )) { chomp $line; $line =~ s/\" $/\"/; ### kludge to remove space after the last dou +blequote, if any print $line . "~~\n"; $status = $csv->parse($line); printf "status=%d\n", $status; unless ($status) { printf "error=%d %s\n", ( $csv->error_diag ()); } @col = $csv->fields(); print Dumper \@col; print "--new line--\n"; } #while
HTH

Rudif