Tux / Text-CSV_XS

perl5 module for composition and decomposition of comma-separated values
17 stars 20 forks source link

consider the number of column names in strict mode #58

Closed XSven closed 3 months ago

XSven commented 3 months ago

There is another strict mode related use case: If I set 3 column_names () in strict mode

$csv->column_names (qw( A B C ));

and then parse () only 2

$csv->parse ('a|b');

I am expecting an exception!

Tux commented 3 months ago

is_missing () and bind_colums () explain why, but also state thtat strict is checked. There might be a conflict in the code for non-streaming parsing (parse ())

strict can be useful, but it proves to be a pita when implementing that for edge cases

Tux commented 3 months ago

I also realise that using parse () in combination with column_names () is implicitely unsupported, as parse () always returns a list of values and never a hash. So maybe just document that this situation would never trigger the expected error.

column_names is to work together with getline_hr. parse is more like getline, which also ignores column_names. What _could* be done - which IMHO would be a good idea - is to make column_names implicitely set the expected number of fields to the number of supplied columns as if a first line was already read (which is not the case: strict bases its failures on the first data-line read.

Note that in your example

$csv->column_names (qw( A B C ));
$csv->parse ("a|b|c");
$csv->parse ("a|b");

will fire an error on that last parse

Tux commented 3 months ago

Ok, try ea3310c6272566891d108323f4204392e3c7cd5d

XSven commented 3 months ago

https://github.com/Tux/Text-CSV_XS/commit/ea3310c6272566891d108323f4204392e3c7cd5d works as expected. Thx again for improving things so quickly! This issue can be closed from my perspective. Any indication when you will provide a new CPAN release?

Tux commented 3 months ago

Thanks for walking the line and quick feedback. It motivates