Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Perl-ish way to create hash from array

by kennethk (Abbot)
on Jul 09, 2013 at 17:30 UTC ( #1043360=note: print w/ replies, xml ) Need Help??


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

I'd consider it Perlish, because it gets the job done and is quite legible. However, you could do it on one line with a map if that feels Perlier to you:

my %csvColumns = map {$csvColumns[$_] => $_} 0 .. $#csvColumns;
Or you could use an explicit iterator with a do to limit scope:
my %csvColumns = do {my $i = 0; map {$_ => $i++} @csvColumns};
I know lots of folks would describe those as Perlier, though would not be using the phrase in a positive way.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


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://1043360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2015-07-08 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (98 votes), past polls