http://www.perlmonks.org?node_id=857036

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

Replies are listed 'Best First'.
Re: Create CSV File
by toolic (Bishop) 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 Tux (Canon) 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
Re: Create CSV File
by ww (Archbishop) 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 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.”