Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

perl hash to CSV using Text::CSV_XS

by perl_war (Initiate)
on Oct 02, 2012 at 20:44 UTC ( #996916=perlquestion: print w/ replies, xml ) Need Help??
perl_war has asked for the wisdom of the Perl Monks concerning the following question:

I wanted to convert a perl hash to csv.

I realize this is easy using Text::CSV::Slurp but performance is better in Text::CSV_XS .

In Text::CSV::Slurp I would use create(input=>$object) function.

In Text::CSV_XS I would use print ($io, $colref); I would have to go through array of hashes line by line and use the above function.

What would be more computationally efficient?

Comment on perl hash to CSV using Text::CSV_XS
Re: perl hash to CSV using Text::CSV_XS
by kcott (Abbot) on Oct 02, 2012 at 21:00 UTC

    G'day perl_war,

    Welcome to the monastery.

    Perl has a builtin module for this task: Benchmark

    -- Ken

Re: perl hash to CSV using Text::CSV_XS
by runrig (Abbot) on Oct 02, 2012 at 21:26 UTC

    Do you really need to store an array of hashes in memory? It might be more 'efficient' to process the data record by record as it is read from the source.

    And if it's not that many records, then I wouldn't worry much about which is more efficient.

Re: perl hash to CSV using Text::CSV_XS
by Tux (Monsignor) on Oct 05, 2012 at 09:58 UTC

    Have you considered DBD::CSV? It uses Text::CSV_XS under the hood (speed), reads all in memory (database tables) and gives you a SQL interface to your data.

    If all you need is to get all CSV into memory as quickly as possible, have a look at Text::CSV_XS' getline_all ()


    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://996916]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-07-11 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls