Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Answer: How do I create a CSV from a 2D array?

by fenonn (Chaplain)
on Jun 08, 2001 at 01:43 UTC ( #86770=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How do I create a CSV from a 2D array? - Answer contributed by fenonn

As long as @data is a 2D array this statement will store the data in CSV form in the scalar $temp so that it can be printed out to a file.
$temp = join "\n", map { $_ = join ",", @{$_} } @data;

Replies are listed 'Best First'.
Re: Answer: How do I create a CSV from a 2D array?
by hossman (Prior) on May 29, 2003 at 23:52 UTC
    This doesn't account for field values which may contain double-quotes, single-quotes, commas, or embedded newlines.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[perldigious]: If you want a linguistic adventure...
[perldigious]: No offense to any Scotsman, I love Scots. Well actually, I love Scotch, but I'm sure the people are great too. :-P
[Discipulus]: perldigious i understand i word on ten, to be optimistic..
LanX will try to give his next LPW talk with a Cogney intonation
[Discipulus]: if you love Scotch in scotland your safety will be.. glengranted
[LanX]: *Cockney

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-06-23 16:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (552 votes). Check out past polls.