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);
In reply to Re: Text::CSV::Slurp losing in getline_hr
by Tux
in thread Text::CSV::Slurp losing in getline_hr
by throop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |