in reply to Need to create CSV using Text::CSV

Hi oldwarrior32,

Change the call to new as follows:

my $csv = Text::CSV->new( { binary => 1, eol => "\n\n" } );

(You will have to adjust the "\n\n" to meet your exact requirements.)

HTH,

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: Need to create CSV using Text::CSV
by oldwarrior32 (Sexton) on Jun 17, 2012 at 03:52 UTC

    I tried but it didn't worked.

    But, and because your illumination, I used:

    $csv->eol ("\r\n");

    and it worked!

    Thanks very much!

    PD: next time I'll try to read the whole doc first.

Re^2: Need to create CSV using Text::CSV
by CountZero (Bishop) on Jun 17, 2012 at 07:50 UTC
    That is surely not going to work correctly. It will create an extra empty line in between each record.

    Update: forget the above. I misread the requirements. Thanks Athanasius for pointing it out.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      It will create an extra empty line in between each record.

      Yes, exactly. The OP wrote:

      I got the following input:

      a,b,c,d,e,f....etc.

      I was hoping something like this:

      a,b

      c,d

      e,f

      etc...

      showing a blank line between each pair of output lines — from which I took it that the extra line was a requirement. But see the caveat at the end of my post.

      Regards,

      Athanasius <°(((><contra mundum

        Indeed, you are right. I missed the extra empty lines.

        Strange kind of CSV file though, with empty lines.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics

        Sorry for the misleading. But I don't want an empty line between the records. I just don't know yet how to post some lines with out empty lines between. I just use the paragraph tag that insert an empty line between written lines. Besides the programs works without empty lines that is what I was looking for.

        Update: I learned already. This is the desired output:

        a,b
        c,d
        e,f
        etc...

        Update2: I think now I undestand what you mean. In a text file the line feed is invisible(at least I don't see blank line between the data using notepad), but when I pasted the data to Excel I saw the blank lines. So, I changed the code to: $csv->eol("\n"); and no blank spaces are seen.

        Thanks!