Z. Charles Dziura
Z. Charles Dziura

Reputation: 933

Is There a Perl Module to Easily Read/Write a CSV File Using User-Configurable Delimiters?

I'm currently optimizing and maintaining a Perl script used to analyze two CSV files for different data. After it's done analyzing the data, the various results are written out to CSV files. However, depending on certain command line flags, the data to be written will be separated by either a comma (,) or a pipe (|). Because of this, the code is a bit convoluted (mostly because the members of my business unit can't code properly to save their lives, but I digress...). I'm wondering if there is a Perl module found somewhere that allows you to read/write files from/to a CSV file, where the delimiters can be configured. I know that Python has a built-in CSV module that allows such functionality and flexibility. When I searched through CPAN, I found the Text::CSV module, but this doesn't seem to allow me to configure the delimiter.

Any thoughts?

Upvotes: 1

Views: 692

Answers (2)

Alex Howansky
Alex Howansky

Reputation: 53573

This should work:

my $csv = Text::CSV->new({
    'escape_char' => '\\',
    'quote_char' => '"',
    'sep_char' => ','
});

Upvotes: 8

runrig
runrig

Reputation: 6524

Also Text::xSV

Upvotes: 2

Related Questions