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)


Enjoy, Have FUN! H.Merijn

In reply to Re^3: Text::CSV_XS and blank lines by Tux
in thread Text::CSV_XS and blank lines by constantreader

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.