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


in reply to Perl-ish way to create hash from array

moritz and tangent have already answered your question. But, I would like to point out something in your code:

Here, you are iterating through the list of column names and building a new list in @csvColumns array.

# figure out the column headings from the first line my @csvColumns = (); foreach my $colName (@{$csvParser->getline($csvHandle)}) { push @csvColumns, $colName; }

In your foreach loop, you are building a (temporary) list by dereferencing the return value of the getline method (@{$csvParser->getline($csvHandle)}), then iterating through this list and copying each element into the other list (push @csvColumns, $colName;), and finally discarding (implicitly) the temporary list.

You could instead do:

# figure out the column headings from the first line my @csvColumns = @{$csvParser->getline($csvHandle)};