Catman...er::CSV(3pm)
π Catmandu::Exporter::CSV π
okay bestie, gather round, because we're talking about Catmandu::Exporter::CSV β aka a CSV exporter β and honestly? it's giving spreadsheet royalty. π
β¨ SYNOPSIS β¨
first up, the command line era, as always:
# 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
and now the Perl script girlies:
# 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;
look at her go π¦
πΈ DESCRIPTION πΈ
so this Catmandu::Exporter takes your items and turns them into rows of comma-separated values (you know her, you love her: CSV). the serialization is based on Text::CSV, no cap. π
if the header option is set, you get a lil header line with the field names at the top β iconic behaviour honestly. and if you wanna know how to configure the field mapping and the column names, go read Catmandu::TabularExporter, she has the tea. β
oh and heads up: newlines and tabulator values inside your field values get escaped as \n, \r, and \t. so your CSV stays cute and un-broken. β¨
hint bestie: by default the exporter outputs all the fields found in the first record of the data input. wanna change that? just set the fields option of the exporter and she'll do what you say. π«Ά
π CONFIGURATION π
the options. the whole options. nothing but the options. let's go. β
fileβ write the output to a local file, given either by its path or by a file handle. OR, plot twist: pass a scalar reference and it writes to a string instead, or pass a code reference and it writes to a callback function. choose your fighter. πfhβ write the output to anIO::Handle. if you don't specify it,Catmandu::Util::iosteps in and builds the output handle from thefileargument, or just usesSTDOUT. easy.fixβ anARRAYof one or more fixes or file scripts that get applied to the exported items. glow-up pass, basically. β¨encodingβ the binmode of the output streamfh. defaults to":utf8"btw, she's already set up for you. πsep_charβ the column separator. defaults to","(comma girl summer).quote_charβ the quotation character. defaults to""".escape_charβ the character used for escaping inside a quoted field. defaults to""".fieldsβ go see Catmandu::TabularExporter, she explains it. πcolumnsβ also see Catmandu::TabularExporter. same deal.headerβ include a header line with the column names. enabled by default, because duh. π
π¦ METHODS π¦
want the full list of methods? okay overachiever, we love that for you. go read:
- Catmandu::TabularExporter
- Catmandu::Exporter
- Catmandu::Addable
- Catmandu::Fixable
- Catmandu::Counter
- Catmandu::Logger
π SEE ALSO π
more reading material, because we stay educated:
Catmandu::Importer::CSV,Catmandu::Exporter::TableCatmandu::Exporter::XLS
and that's the whole page bestie π β this lil masterpiece shipped with perl v5.40.1 and was dated 2026-01-24, so go forth and export some absolute slay. periodt. π
β¨
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms