Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Text::CSV_XS - strict mode and EOF

by Anonymous Monk
on Mar 14, 2019 at 04:28 UTC ( #1231244=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, everyone: I'm running into a strange (to me) behavior of Text::CSV_XS (1.38, running on 5.10), and I'm unsure how to canonically handle it. When using strict mode of Text::CSV_XS, e.g:
#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; my $file = $ARGV[0]; my $xs = Text::CSV_XS->new({'strict' => 1,'auto_diag' => 2}); open(my $handle,$file); $xs->column_names(['one','two','three']); while(my $line = $xs->getline($handle)) { print Dumper($line)."\r\n"; } close($handle);
With the following CSV file:
$ cat test.csv this,is,a test,of,the csv,parser,logic
I receive the following output:
$ ./csv_test.pl test.csv $VAR1 = [ 'this', 'is', 'a' ]; $VAR1 = [ 'test', 'of', 'the' ]; $VAR1 = [ 'csv', 'parser', 'logic' ]; # CSV_XS ERROR: 2014 - ENF - Inconsistent number of fields @ rec 4 pos + 1
where rec 4 is a non-existent line below "csv,parser,logic". There are no extraneous line breaks, or extra line endings. My expectation would be that EOF would skip the strictness check, but this does not appear to be the case. This does not occur without the strict option enabled. Is there a canonical approach recommended for using strict => 1 in the manner outlined above? Thanks in advance.

Replies are listed 'Best First'.
Re: Text::CSV_XS - strict mode and EOF
by Tux (Abbot) on Mar 14, 2019 at 09:26 UTC

    Thanks for spotting this. Fixed in this commit. I am sorry for the inconvenience this caused.

    I'll start the test cycles soon and see if I can make a release. $work however takes precedence and is very busy.


    Enjoy, Have FUN! H.Merijn

      No worries at all, I just wasn't sure if I was somehow using the module/mode incorrectly.

      Thanks for the prompt investigation/resolution!

        I just released Text-CSV_XS-1.39:

        • Fix tests to skip on Encode failing (PR#17 charsbar + klapperl)
        • Tested on Z/OS (s390x - Hercules) :)
        • Test with new Module::CPANTS::Analyse
        • Add options -w/-b/-Z to csvdiff
        • Fix strict on streaming EOF <--- this was your case
        • Now also tested with cperl

        This release took two days, tested on 17 OS's with several architectures, against 900+ modules that directly or indirectly require it

        Enjoy, and thanks to all who keep reporting problems or ask for features!


        Enjoy, Have FUN! H.Merijn
Re: Text::CSV_XS - strict mode and EOF
by choroba (Bishop) on Mar 14, 2019 at 08:33 UTC
    EOF error is ignored under the strict mode, but it seems it doesn't turn off other errors that might follow. I'm not sure whether it's OK to skip all the errors on EOF, though - what if the last row really had an incorrect number of fields? Tux will tell us more.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1231244]
Approved by Paladin
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2019-03-20 15:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (101 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!