Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
With the following CSV file:#!/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);
I receive the following output:$ cat test.csv this,is,a test,of,the csv,parser,logic
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.$ ./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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text::CSV_XS - strict mode and EOF
by Tux (Canon) on Mar 14, 2019 at 09:26 UTC | |
by Anonymous Monk on Mar 15, 2019 at 02:36 UTC | |
by Tux (Canon) on Mar 16, 2019 at 11:18 UTC | |
by hippo (Archbishop) on Mar 16, 2019 at 12:04 UTC | |
|
Re: Text::CSV_XS - strict mode and EOF
by choroba (Cardinal) on Mar 14, 2019 at 08:33 UTC |