|XP is just a number|
Re: Low-threshold function in Text::CSV_XSby Tux (Monsignor)
|on Feb 06, 2014 at 08:44 UTC||Need Help??|
I have just uploaded Text-CSV_XS-1.04, which has defined the new functionality like this:
This function is not exported by default and should be explicitly requested:use Text::CSV_XS qw( csv );
This is the first draft. This function will stay, but the arguments might change based on user feedback: esp. the headers attribute is not complete. The basics will stay.
This is an high-level function that aims at simple interfaces. It can be used to read/parse a CSV file or stream (the default behavior) or to produce a file or write to a stream (define the out attribute). It returns an array reference on parsing (or undef on fail) or the numeric value of "error_diag" on writing. When this function fails you can get to the error using the class call to "error_diag"
This function takes the arguments as key-value pairs. It can be passed as a list or as an anonymous hash:
If not overridden, the default options used for CSV areauto_diag => 1
These options are always set and cannot be alteredbinary => 1
Used to specify the source. in can be a file name (e.g. "file.csv"), which will be opened for reading and closed when finished, a file handle (e.g. $fh or FH), a reference to a glob (e.g. \*ARGV), or - when your version of perl is not archaic - the glob itself (e.g. *STDIN).
When used with "out", it should be a reference to a CSV structure (AoA or AoH).
In output mode, the default CSV options when producing CSV areeol => "\r\n"
The "fragment" attribute is ignored in output mode.
out can be a file name (e.g. "file.csv"), which will be opened for writing and closed when finished, a file handle (e.g. $fh or FH), a reference to a glob (e.g. \*STDOUT), or - when your version of perl is not archaic - the glob itself (e.g. *STDOUT).
If passed, it should be an encoding accepted by the :encoding() option to open. There is no default value. This attribute does not work in perl 5.6.x.
If this attribute is not given, the default behavior is to produce an array of arrays.
If headers is given, it should be either an anonymous list of column names or a flag: auto or skip. When skip is used, the header will not be included in the output.my $aoa = csv (in => $fh, headers => "skip");
If auto is used, the first line of the CSV source will be read as the list of field headers and used to produce an array of hashes.my $aoh = csv (in => $fh, headers => "auto");
If headers is an anonymous list, it will be used instead
Combining all of them could give something like
Thanks for all the feedback I got!
Enjoy, Have FUN! H.Merijn