in reply to Re: text::csv output help
in thread text::csv output help

thanks. btw, it has to be an array ref. $csv->print ($fh, $_) for \@rows; instead of @rows as it appears in the documentation.

Replies are listed 'Best First'.
Re^3: text::csv output help
by ikegami (Patriarch) on Nov 30, 2010 at 23:05 UTC

    No, the documentation is correct.

    $csv->print($fh, $_) for @rows;
    and
    $csv->print($fh, \@row);
    make sense, but not
    $csv->print($fh, $_) for \@rows;

    I imagine that your @rows didn't actually contain rows.

      @rows is supposed to contain a 2-d array? Can you give an example of the format? The error I get: "Expected fields to be an array ref at line x". Thx, Dave

        print expects a file handle and a reference to an array of field values.

        my @row = qw( 1 2 3 4 5 'hello world'); $csv->print($fh, \@row);
      What are the rows supposed to contain? How do you keep track of rows, they are all appearing on one line. Should I insert the "\n" character in somewhere? Otherwise I get the error: Expected fields to be an array ref at path line x. Say for example I wanted to make 2 rows of a CSV file, can you provide some code to do that? Regards, Dave

        $csv->print (...) only prints a newline if it is told to do so. You can tell it to do so either in the constructor

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

        Or at a leter stage

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

        Enjoy, Have FUN! H.Merijn