Jenda Krynicky wrote:
From: "Bill Harpley" <bill.harp...@ericsson.com>
Suppose I have a multidimensional array of the form:

@array[names][values]

For example, I have a list of database field names and the value
associated with each one.

If this was a single dimensional array called @list, I could create an
output line in CSV format by using the 'join' command like this:

$line= join ',' , @list;

Is there a simple way to just take a single column of a multidimensional
array and use 'join' to create a CSV output line?

Must I copy the desired column into a single dimensional array first?
This is the most obvious way but if anybody can think of a neater trick
I would be delighted to know !

I believe you are looking for

 $line = join ',', map $_[$column_index], @array;


The map() selects the right item from each row and creates a list of the values in the column.

@array contains array references so that *should* be:

$line = join ',', map $_->[$column_index], @array;



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to