Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Populating a CSV file with Text::CSV_XS

by master_son (Acolyte)
on Jan 26, 2006 at 21:52 UTC ( #525850=perlquestion: print w/replies, xml ) Need Help??

master_son has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a method of writing form data to a CSV file. I know of Text::CSV_XS, but I am confused on the matter of

$status = $csv->print(\*OUT, $columns)

assuming I have

 $CSV =Text::CSV_XS->new()

earlier, and an array @columns the CPAN manpage says the $columns perameter must be scalar reference to an array. How can I reference the array when both the array and the above statement are in the same subroutine?

---------------------
Keep your concentration here and now where it belongs - Qui-Gon Jinn

Replies are listed 'Best First'.
Re: Populating a CSV file with Text::CSV_XS (\)
by tye (Sage) on Jan 26, 2006 at 22:27 UTC
    \@columns

    And note that $csv and $CSV aren't the same variable.

    See also perlreftut ?

    - tye        

Re: Populating a CSV file with Text::CSV_XS
by BMaximus (Chaplain) on Jan 26, 2006 at 22:31 UTC
    The docs say that it takes a reference to an array. So:
    my @columns = (qw/what ever the items are for each columns/); $csv = Text::CSV_XS->new(); # $io is a filehandle from IO::File which has a print method. A glob d +oes not. $status = $csv->print($io, \@columns);
    Use IO::File to make the filehandle. Not a glob as from what I understand the handle needs a print method in order for this to work.

    BMaximus
      Thanks BMaximus, I actually used IO::File to write the csv, which looks easier.
      ---------------------
      Keep your concentration here and now where it belongs - Qui-Gon Jinn
Re: Populating a CSV file with Text::CSV_XS
by jZed (Prior) on Jan 26, 2006 at 22:30 UTC
    I'm not sure exactly what you're asking, but these two are the same thing:
    my $columns = [ 1, "foo", 3 ]; $csv->print( \*OUT, $columns); # ... my @columns = ( 1, "foo", 3 ); $csv->print( \*OUT, \@columns);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://525850]
Approved by kutsu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-10-03 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (13 votes). Check out past polls.

    Notices?