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

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.

Replies are listed 'Best First'.
Re^4: text::csv output help
by dmn001 (Initiate) on Dec 01, 2010 at 00:03 UTC
    @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);
Re^4: text::csv output help
by dmn001 (Initiate) on Dec 01, 2010 at 00:45 UTC
    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