The default behavior for
Text::CSV_XS works as you want things to. Example:
use strict;
use Text::CSV_XS;
use IO::File;
my $csv = Text::CSV_XS->new();
my @row;
while (<DATA>)
{
chomp;
@row = split(/\|/, $_);
$csv->print(\*STDOUT, \@row);
print "\n";
}
__DATA__
Field1|Field Number Two|Field Number Three|Field4
Another One|foo|fubar|foo and fubar
produces:
Field1,"Field Number Two","Field Number Three",Field4
"Another One",foo,fubar,"foo and fubar"
I've found Text::CSV_XS
to be the most accurate at generating true CSV, versus
just delimited by commas, which some people seem to think
is CSV.