Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9b731b3b1f
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (23 sloc) 1.329 kB
Simple CSV (comma-separated values) format parser for Perl 6.
use v6;
use Text::CSV;
say Text::CSV.parse-file('somefile.csv').perl;
say Text::CSV.parse("foo,bar\nbaz,boo").perl;
Oh, and the C<parse> methods take the following named parameters:
:trim Removes whitespace on both ends of each value.
:skip-header Causes the first line not to be included in the output.
:strict Throws an error if a row has a different number of columns
than the previous ones.
:output Determines the shape of the returned data structure.
Allowed values are 'arrays' (the default), 'hashes',
and any type object (i.e. ':output(MyType)').
When the value is 'hashes' or a type object, the first line
is assumed to be a special header line, the values on that
line are used as hash keys, and :skip-header is suppressed.
If you see yourself regularly contravening the defaults of one or more of
these parameters, it might be a good idea to instantiate the Text::CSV
class, giving it the default values you want:
my $parser = Text::CSV.new( :output<hashes>, :!strict );
my Hash[Str] @hashes = $parser.parse-file('somefile.csv');
== License
This module is released under Artistic 2.0. See LICENSE.
Jump to Line
Something went wrong with that request. Please try again.