Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Create CSV File

by PerlScholar (Acolyte)
on Aug 24, 2010 at 22:55 UTC ( #857036=perlquestion: print w/ replies, xml ) Need Help??
PerlScholar has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

Perl newbie here. I'm trying to create a simple CSV file to be read into Excel. From a brief investigation it seems that the best option is using the Text::CSV module is this true? (I've found alot of stuff about parsing CSV files using Text::CSV but not so much on creating them). The file that i'm trying to create should look something like the following. Any help would be great. Thanks :)

Player, Country, Position
Rooney, England, Striker
Kaka, Brazil, Midfielder
Lahm, Germany, Defender

Comment on Create CSV File
Re: Create CSV File
by toolic (Chancellor) on Aug 24, 2010 at 23:05 UTC
    it seems that the best option is using the Text::CSV module is this true?
    Using Text::CSV is a recommended way to create a CSV file. Whether it is the "best" way depends on what requirements you have. Try it out and see if it suits your purposes. See also Text::CSV_XS.
Re: Create CSV File
by sundialsvc4 (Abbot) on Aug 24, 2010 at 23:40 UTC

    I strongly agree with the above.   CPAN provides you with a cornucopia of tested tools for doing a great many things... simple things, like this one, and immensely complex things too.   IMHO, it is always advisable to “search CPAN first,” and to use what you find there in preference to “rolling your own.”

    If you’re not sure whether you will continue using a particular package as your application grows, simply build an application-specific “wrapper” package (of your own design) that properly reflects its calls to the CPAN module(s) of choice.   This will confine any future re-implementation efforts to that one “wrapper.”

Re: Create CSV File
by ww (Bishop) on Aug 25, 2010 at 00:00 UTC
    I'm trying to create a simple CSV file...
    OK, but...
    to be read into Excel

    So, is there some reason not to create (or modify) the Excel file directly?

    If not, you may want to read the docs for modules of the Spreadsheet::... family and to search (Google, Super Search) for "Excel" on this site for additional options.

Re: Create CSV File
by Tux (Monsignor) on Aug 25, 2010 at 05:11 UTC

    Creating a CSV before Excel does have some advantages, though both formats are portable. Text::CSV_XS comes with csv2xls is the examples folder with many options to convert CSV to Excel.


    Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-12-22 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls