Dear Monks, I want to create a CSV File using Text::CSV. I was able to do the thing by hand but I would like to create it using the module.

I have this:

my @AoA= (['a', 'b'], ['c', 'd'], ... and so on); my $csv = Text::CSV->new ( { binary => 1 } ); open my $fh, ">", "new.text"; $csv->print ($fh, $_) for @AoA; close $fh;

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...

When i use the Text::Table module, I pass to the load function the @AoA array, and I got a nice table. But with the Text::CSV module doesn't work.

I read the Text::CSV doc and It says I need to pass an array reference to the print function. But if I do that I got this:

my @AoA= (['a', 'b'], ['c', 'd'], ... and so on); my $aref = \@AoA; my $csv = Text::CSV->new ( { binary => 1 } ); open my $fh, ">", "new.text"; $csv->print ($fh, $aref) for @AoA; $csv->print ($fh, $aref);#tried this too. close $fh

Ouput:(0x146ad74),ARRAY(0x1496524),ARRAY(0x14448ec),ARRAY(0x1157ec4),etc..

What I am doing wrong?

Thanks for your help!


In reply to Need to create CSV using Text::CSV by oldwarrior32

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.