Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl-ish way to create hash from array

by PrakashK (Pilgrim)
on Jul 09, 2013 at 20:58 UTC ( #1043376=note: print w/ replies, xml ) Need Help??


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)};


Comment on Re: Perl-ish way to create hash from array
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-08-30 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls