Catman...er::CSV(3pm)
β¨ NAME β¨
okay so bestie, meet Catmandu::Importer::CSV β the little package that imports CSV data π this is the Catmandu::Importer::CSV(3pm) manual page and she is literally here to feed you spreadsheets.
π SYNOPSIS π
from the command line, babes:
# 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];
# ...
});
πΈ DESCRIPTION πΈ
so this package imports comma-separated values (CSV) β no cap, that's her whole job π«Ά
the object fields get read from the CSV header line, or you can hand them over yourself with the fields parameter.
strings inside the CSV are quoted by quote_char, and the fields are separated by sep_char. that's the vibe π
π¦ CONFIGURATION π¦
okay this is the part where she tells you all her lil settings, and there are a LOT, so buckle up π
fileβ read input from a local file by giving its path. alternatively, you can pass a scalar reference and she'll read from that string instead β¨fhβ read input from anIO::Handle. if you don't specify one,Catmandu::Util::iogets called to build the input stream from thefileargument, or else it just uses STDIN πencodingβ the binmode of the input streamfh. defaults to:utf8πΈfixβ an ARRAY of one or more fixes, or file scripts, that get applied to the imported items. lil glow-up for your data πfieldsβ the list of fields to use as columns. you can give it as an array reference, a comma-separated string, or a hash reference. important: ifheaderis0andfieldsisundef, the fields get named by column index β0,1,2, ... and so on πheaderβ read the fields from a header line with the column names. set it to1to do that, and1is the default, so she's doing it unless you say otherwise πsep_charβ the column separator. default is,β¨quote_charβ the quotation character. default is"πescape_charβ the character used for escaping inside a quoted field. default is"πallow_loose_quotesallow_loose_escapesβ allow the common bad-practice stuff in CSV escaping. yes bestie, we're being lenient π
π METHODS π
every Catmandu::Importer is a Catmandu::Iterable, so literally all of its methods are inherited. she's got main character energy by association π
heads up though: these methods are NOT idempotent. a CSV stream can only be read once β one shot, that's it, no reruns π
π SEE ALSO π
go check out her friends, they're iconic:
Catmandu::Exporter::CSVCatmandu::Importer::XLS
that's the whole page, bestie π«Ά this was perl v5.40.1, dated 2026-01-24, and it lives in Catmandu::Importer::CSV(3pm) in the User Contributed Perl Documentation β mwah, 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