Catmandu::Importer::CSV - Package that imports CSV data
# From the command line # convert a CSV file to JSON catmandu convert CSV to JSON < journals.csv # set column names if CSV file has no header line echo '12157,"The Journal of Headache and Pain",2193-1801' | \ catmandu convert CSV --header 0 --fields 'id,title,issn' to YAML # set field separator and quote character echo '12157;$The Journal of Headache and Pain$;2193-1801' | \ catmandu convert CSV --header 0 --fields 'id,title,issn' --sep_char ';' --quote_char '$' to XLSX --file journal.xlsx # In a Perl script use Catmandu; my $importer = Catmandu->importer('CSV', file => "/foo/bar.csv"); my $n = $importer->each(sub { my $hashref = $_[0]; # ... });
The package imports comma-separated values (CSV). The object fields are read from the CSV header line or given via the fields parameter. Strings in CSV are quoted by quote_char and fields are separated by sep_char.
fields
quote_char
sep_char
Read input from a local file given by its path. Alternatively a scalar reference can be passed to read from a string.
Read input from an IO::Handle. If not specified, Catmandu::Util::io is used to create the input stream from the file argument or by using STDIN.
file
Binmode of the input stream fh. Set to :utf8 by default.
fh
:utf8
An ARRAY of one or more fixes or file scripts to be applied to imported items.
List of fields to be used as columns, given as array reference, comma-separated string, or hash reference. If header is 0 and fields is undef the fields will be named by column index ("0", "1", "2", ...).
header
0
undef
Read fields from a header line with the column names, if set to 1 (the default).
1
Column separator (, by default)
,
Quotation character (" by default)
"
Character for escaping inside quoted field (" by default)
Allow common bad-practice in CSV escaping
Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The methods are not idempotent: CSV streams can only be read once.
Catmandu::Exporter::CSV, Catmandu::Importer::XLS
To install Catmandu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catmandu
CPAN shell
perl -MCPAN -e shell install Catmandu
For more information on module installation, please visit the detailed CPAN module installation guide.