|
|
| more useful options | |
| PerlMonks |
Re: CSV headers. Feedback wantedby Tux (Canon) |
| on Feb 16, 2016 at 15:40 UTC ( [id://1155364]=note: print w/replies, xml ) | Need Help?? |
|
All feedback weighed, I have now committed and pushed: headerThis method does NOT work in perl-5.6.x Parse the CSV header and set sep_char and encoding.
The first argument should be a file handle. Assuming that the file opened for parsing has a header, and the header does not contain problematic characters like embedded newlines, read the first line from the open handle, auto-detect whether the header separates the column names with a character from the allowed separator list. That list defaults to [ ";", "," ] and can be overruled with an optional argument of an anonymous list of allowed separator sequences. If any of the allowed separators matches, and none of the other allowed separators match, set sep_char to that sequence for the current CSV_XS instance and use it to parse the first line, map those to lowercase, use that to set the instance column_names and return the instance:
If the header is empty, contains more than one unique separator out of the allowed set, contains empty fields, or contains identical fields (after folding), it will croak with error 1010, 1011, 1012, or 1013 respectively. This method will return the instance on success or undefined on failure if it did not croak. Options
Enjoy, Have FUN! H.Merijn
In Section
Meditations
|
|
||||||||||||||||||||||||||||||