Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Parsing MS SQL CSV export with Text::CSV_XS

by Tux (Abbot)
on Oct 22, 2008 at 19:16 UTC ( #718841=note: print w/replies, xml ) Need Help??


in reply to Parsing MS SQL CSV export with Text::CSV_XS

If you suspect errors, don't use ->status (), but ->error_diag ().

If you expect weird characters, you can use my new module Data::Peek:

use Text::CSV_XS; use Data::Peek; my $csv = Text::CSV_XS->new ({ binary => 1 }); $csv->parse (qq{"ab\nc\x{20ac}\x80"}); print DPeek, "\n" for $csv->fields; $csv->parse (qq{"ab\nc\x{20ac}\x80",\r"\n}); $csv->error_diag;

Will return

PV("ab\nc\342\202\254\302\200"\0) [UTF8 "ab\nc\x{20ac}\x{80}"] # CSV_XS ERROR: 2031 - EIF - CR char is first char of field, not part +of EOL

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Parsing MS SQL CSV export with Text::CSV_XS
by andyford (Curate) on Oct 22, 2008 at 20:04 UTC

    You got me thinking. If I take out the getline and put the parse in the loop and add your error_diag(),

    use strict; use warnings; use Text::CSV_XS; my $tr_csv = Text::CSV_XS->new({ binary => 1, eol => $/ }); open(my $tr,"<",'file.csv') or die "Failure opening ERS data file: $!" +; while (my $row = <$tr>) { $tr_csv->parse($row); print $tr_csv->error_diag(),"\n"; }
    I can get some errors.
    2032EIF - CR char inside unquoted, not part of EOL436 2032EIF - CR char inside unquoted, not part of EOL435 2032EIF - CR char inside unquoted, not part of EOL433 2032EIF - CR char inside unquoted, not part of EOL425 2032EIF - CR char inside unquoted, not part of EOL425
    I guess that means it's worse than just having two extra characters at the beginning.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://718841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2020-01-23 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?