++ed by:
JONASS VOJ

2 PAUSE users
4 non-PAUSE users.

Nicolas Steenlant
and 15 contributors

NAME

Catmandu::Exporter::CSV - a CSV exporter

SYNOPSIS

    use Catmandu::Exporter::CSV;

    my $exporter = Catmandu::Exporter::CSV->new(
                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 objects\n" , $exporter->count;

DESCRIPTION

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. Field names can be read from the first item exported or set by option fields. Newlines and tabulator values are in field values are escaped as \n, \r, and \t.

CONFIGURATION

file

Write output to a local file given by its path or file handle. Alternatively a scalar reference can be passed to write to a string and a code reference can be used to write to a callback function.

fh

Write the output to an IO::Handle. If not specified, Catmandu::Util::io is used to create the output handle from the file argument or by using STDOUT.

fix

An ARRAY of one or more fixes or file scripts to be applied to exported items.

encoding

Binmode of the output stream fh. Set to ":utf8" by default.

sep_char

Column separator (, by default)

quote_char

Quotation character (" by default)

escape_char

Character for escaping inside quoted field (" by default)

fields

List of fields to be used as columns, given as array reference, comma-separated string, or hash reference.

Include a header line with the column names, if set to 1 (the default). Custom field names can be supplied as hash reference. By default field names are used as as column names.

METHODS

See Catmandu::Exporter, Catmandu::Addable, Catmandu::Fixable, Catmandu::Counter, and Catmandu::Logger for a full list of methods.

SEE ALSO

Catmandu::Importer::CSV, Catmandu::Exporter::Table Catmandu::Exporter::XLS