Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: dump text file in ASCII and hex by Rudif
in thread dump text file in ASCII and hex by kevind0718

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-18 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found