H.Merijn Brand, the Text::CSV_XS maintainer has been dicussing possibilities for adding parsing rows as hashrefs to that module through this RT ticket.
As fate would have it, our efforts to implement it crossed paths, and we now both have fairly complete but somewhat different patches for the feature. A couple points to get feedback on:
Which you do find clearer for setting the column names to use as the hash keys:
I have already been confused about whether "hr" stood for "header row" or "hashref", so I vote for the former.
The second point, which is currently in neither patch, is "how you design the interface to automatically setting the column names from the first row of the CSV?"
Parse::CSV uses new( fields => 'auto' ), but involving new() won't work for Text::CSV_XS.
I was thinking of perhaps:
Which would simply mean:
$csv->column_names( $csv->getline($io) );
We would leave it up to documentation to make sure users called this first thing.
Alternately, you could have a function that stores the current file position, rewinds and reads the first row, and then returns to the current position. That seems more fragile to me, and I can oly imagine there are some non-rewindable filehandles out there for which it wouldn't work.
You can leave feedback here and/or in the RT ticket.