As the _hr variants are the odd one out in the code, counting fields inside the parser actually was kinda awkward. And the only way to do it reliable - as far as I could see in my first try - was definitely not doing any good to the parsing speed of "regular" parses. All the other parse methods return an araay or an array reference. That means that you can very easily check the length of the array to see how many fields were parsed.
What I did instead, was this:
is_missing my $missing = $csv->is_missing ($column_idx); Where $column_idx is the (zero-based) index of the column in th +e last result of "getline_hr". while (my $hr = $csv->getline_hr ($fh)) { $csv->is_missing (0) and next; # This was an empty line } When using "getline_hr" for parsing, it is impossible to tell i +f the fields are "undef" because they where not filled in the CSV str +eam or because they were not read at all, as all the fields defined by "column_names" are set in the hash-ref. If you still need to kn +ow if all fields in each row are provided, you should enable "keep_me +ta_info" so you can check the flags.
Your constructor would then look somewhat like
my $csv = Text::CSV_XS->new ({ auto_diag => 1, binary => 1, keep_meta_info => 1, });
Tell me if that would work for you ... (BTW feel free to pull from here)
In reply to Re^3: Text::CSV_XS and blank lines
by Tux
in thread Text::CSV_XS and blank lines
by constantreader
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |