| Catmandu::Exporter::CSV(3pm) | User Contributed Perl Documentation | Catmandu::Exporter::CSV(3pm) |
Catmandu::Exporter::CSV - a CSV exporter
# On the command line
$ catmandu convert XSL to CSV < data.xls
$ catmandu convert JSON to CSV --fix myfixes.txt --sep_char ';' < data.json
# Provide a hint to the exporter which fields to export from the JSON
# input. By default the CSV exporter will export the fields that are
# found in the first JSON record.
$ catmandu convert JSON to CSV --fields "id,title,year" < data.json
# In a Perl script
use Catmandu;
my $exporter = Catmandu->exporter('CSV',
fix => 'myfix.txt',
quote_char => '"',
sep_char => ',',
escape_char => '"' ,
always_quote => 1,
header => 1);
$exporter->fields("f1,f2,f3");
$exporter->fields([qw(f1 f2 f3)]);
$exporter->add_many($arrayref);
$exporter->add_many($iterator);
$exporter->add_many(sub { });
$exporter->add($hashref);
printf "exported %d items\n" , $exporter->count;
This "Catmandu::Exporter" exports items as rows with comma-separated values (CSV). Serialization is based on Text::CSV. A header line with field names will be included if option "header" is set. See Catmandu::TabularExporter on how to configure the field mapping and column names. Newlines and tabulator values in field values are escaped as "\n", "\r", and "\t".
Hint: by default, the exporter will output all the fields that are found in the first record of the data input. This can be changed by setting the "fields" option of the exporter.
See Catmandu::TabularExporter, Catmandu::Exporter, Catmandu::Addable, Catmandu::Fixable, Catmandu::Counter, and Catmandu::Logger for a full list of methods.
Catmandu::Importer::CSV, Catmandu::Exporter::Table Catmandu::Exporter::XLS
| 2025-01-17 | perl v5.40.0 |