FWIW Text::CSV_XS (and Text::CSV - which uses Text::CSV_XS if installed - used in Text::CSV::Slurp), have a native method that comes very close to what you are using: getline_hr_all since version 0.80 (2010-12-24).

Note that the documentation of Text::CSV::Slurp does not mention that a header line is required in the CSV file. Your statement "On the first line of data, Slurp calls $csv->getline_hr ($io)" is not true. It does so for the second line. The first line is read with if (my $head = $csv->getline ($io)) { $csv->column_names ($head); ...

In Text::CSV_XS speak, your code would be something like:

use strict; use warnings; use Text::CSV_XS; my $file = "/orion-reqs/SaferHtml/CradleCSV/2012_03_30/Doc_Sections_SA +FER_Group_Trace.csv"; open my $fh, "<:encoding(utf-8)", $file or die "$file: $!"; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); $csv->column_names ($csv->getline ($fh)); my $data = $csv->getline_hr_all ($fh); close ($fh);

Enjoy, Have FUN! H.Merijn
/b

In reply to Re: Text::CSV::Slurp losing in getline_hr by Tux
in thread Text::CSV::Slurp losing in getline_hr by throop

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.