This took me a while, and brought me to some new dark corners of XS code :)
No, you do not need Dumper. In fact, you should never need Dumper. Data::Dumper is for debugging, not for production code. But that aside. The code I showed you should have worked from the perl side of view. $sth->{NAME_lc} returns a reference to a list, but in this case, as it is a statement handle from DBI, it is not a plain reference, but a reference with magig attached, and Text::CSV_XS cannot deal with that (yet). So the solution might be:
$csv->print (*STDOUT, [@{$sth->{NAME_lc}}]);
Which dereferences the reference to a list, and puting it back in an anonymous array again. That line would deserve some comment in production code :)
So, your final code should look like this:
my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" }); $csv->print (*STDOUT, [@{$_read_sth->{NAME}}]); while (my $row = $_read_sth->fetchall_arrayref) { # If you need to add other headers ... $csv->print (*STDOUT, [qw( some different header )]) if $needed; # print the data fetched $csv->print (*STDOUT, $row); }
In reply to Re^5: Formatting question??
by Tux
in thread Formatting question??
by sudip_dg77
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |