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); }

Enjoy, Have FUN! H.Merijn

In reply to Re^5: Formatting question?? by Tux
in thread Formatting question?? by sudip_dg77

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.