badaiaqrandista has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks

Is there any way we can put line feed (\n) into a content in a CSV created by Text::CSV?

I know the documentation said that 'A CSV string may be terminated by 0x0A (line feed) or by 0x0D,0x0A (carriage return, line feed)'. However, the wikipedia definition of CSV mentions that 'a line break within an element must be preserved'. Although wikipedia is not the authority that set the CSV standard (if there is the CSV standard), I'd like to know whether a workaround exists to insert a line feed (\n) in a CSV field using Text::CSV. Can anyone point me somewhere?

Thank you

-cheepy-

Replies are listed 'Best First'.
Re: Using line feed with Text::CSV
by Zaxo (Archbishop) on Jun 05, 2006 at 02:26 UTC

    Text::CSV is not quite flexible enough for that. Its big brother, Text::CSV_XS, will allow carriage returns within fields if you set the 'binary' attribute true.

    Text::CSV_XS is used internally by the DBD::CSV driver for DBI. That is, in my opinion, the finest way to handle csv files.

    After Compline,
    Zaxo

Re: Using line feed with Text::CSV
by dragonchild (Archbishop) on Jun 05, 2006 at 02:59 UTC
    Alternately, Text::xSV correctly handles linebreaks and other CSV oddities.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Using line feed with Text::CSV
by badaiaqrandista (Pilgrim) on Jun 05, 2006 at 03:06 UTC

    Nice one!!! Thanks guys. I guess I'll just use Text::CSV_CS.

    -cheepy-