NAME

Catmandu::Importer::CSV - Package that imports CSV data

SYNOPSIS

use Catmandu::Importer::CSV;

my $importer = Catmandu::Importer::CSV->new(file => "/foo/bar.csv");

my $n = $importer->each(sub {
    my $hashref = $_[0];
    # ...
});

Convert CSV to other formats with the catmandu command line client:

# convert 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

METHODS

new(file => $filename, fh = $fh, fields => \@fields, quote_char => "\"", sep_char => ",", fix => [...])

Create a new CSV importer for $filename. Use STDIN when no filename is given. 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'.

The constructor inherits the fix parameter from Catmandu::Fixable. When given, then ech fix or fix script will be applied to imported items.

count

each(&callback)

...

Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The Catmandu::Importer::CSV methods are not idempotent: CSV streams can only be read once.

SEE ALSO

Catmandu::Iterable