I am using Text::CSV_XS
to create CSV files. I see that if a field has a space then it is outputted within double quotes e.g.
john,smith,"Some address",,,,bla
I was wondering are the double quotes mandatory in the example? Or is it some configuration option?
As Subbeh has already suggested, you can set quote_char
to undef when calling new
, to suppress this, as per https://metacpan.org/pod/Text::CSV_XS#new
I'd question whether you should, though. In the CSV specification, https://www.rfc-editor.org/rfc/rfc4180, these quotes are always permitted and sometimes necessary (although strictly only when the field contains a separator character or a quote character itself). Since it's perfectly valid for them to be there, and any CSV-parsing tool you pass the data to later will cope ... I'd be inclined to let Text::CSV do its thing.
In particular, if you set quote_char
to undef as suggested, fields which contain sep_char
(comma, usually) will lead to breakage.
Edit: You can set quote_space
to a false value in your call to new
to prevent this specific behaviour (of quoting fields with spaces in), which the CSV spec neither mandates nor prohibits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With