Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Writing CSV files

by steves (Curate)
on Oct 29, 2004 at 09:50 UTC ( #403662=note: print w/replies, xml ) Need Help??

in reply to Writing CSV files

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
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.

Replies are listed 'Best First'.
Re^2: Writing CSV files
by tachyon (Chancellor) on Oct 29, 2004 at 12:03 UTC

    The default behavior for Text::CSV_XS works as you want things to.

    Actually what you have shown and what Text::CSV_XS does has no relationship whatsoever to what the OP wanted.

      You are correct tachyon. It took me three cups of coffee to see that. My apologies. The issue here is rather custom since none of the CSV packages I've used will tell you if something was quoted coming in -- they hide that. It seems like to do this right you need to know what was quoted coming in and mirror that on the way out. If the rules are based on content (e.g., something that can be regexp matched) then maybe you don't need to know how it was originally.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://403662]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-11-18 22:26 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (206 votes). Check out past polls.