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

perltux has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have an array and want to convert it into a hash where the array values become the keys and the array index numbers become the values of the hash.
The following code does this, but I wonder if there is a more elegant and/or efficient way of doing this?
(The content of the array could be anything, not necessarily the letter sequence I used in my example below)

my @array=qw(a b c d e f g h); my %hash; for (my $idx=0; $idx<@array; $idx++) { $hash{$array[$idx]} = $idx; }