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?

( #46542=categorized answer: print w/ replies, xml ) Need Help??

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

As long as you are sure the list is two dimensional, this should work. First argument is the delimiter, second is the array. If you print the returned scalar to a filehandle, you will create a .csv file:
-------
my $write_this_to_file = delimit( ", ", @array ); sub delimit { my $delim = shift; my $delimited_file; foreach $row (@_) { $delimited_file .= join ($delim, @$row); $delimited_file .= "\n"; } return $delimited_file; }

Comment on Answer: How do I create a CSV from a 2D array?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-09-16 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (50 votes), past polls