oldwarrior32 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need to create CSV using Text::CSV
by Athanasius (Archbishop) on Jun 17, 2012 at 03:22 UTC | |
by oldwarrior32 (Sexton) on Jun 17, 2012 at 03:52 UTC | |
by CountZero (Bishop) on Jun 17, 2012 at 07:50 UTC | |
by Athanasius (Archbishop) on Jun 17, 2012 at 08:46 UTC | |
by CountZero (Bishop) on Jun 17, 2012 at 14:28 UTC | |
by oldwarrior32 (Sexton) on Jun 17, 2012 at 17:14 UTC | |
by Tux (Canon) on Jun 18, 2012 at 06:41 UTC | |
| |
|
Re: Need to create CSV using Text::CSV
by frozenwithjoy (Priest) on Jun 17, 2012 at 03:07 UTC | |
by oldwarrior32 (Sexton) on Jun 17, 2012 at 03:49 UTC |