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


in reply to better array to hash conversion

While the hash slice method is the most idiomatic, here's one more variation, based on the OP's code -- just taking out the C-like for loop:

$hash{ $array[$_] } = $_ for (0..$#array);

And something that works only after 5.12 but is very easy to read:

use 5.012; while (my ($idx, $val) = each(@array)) { $hash{$val} = $idx; }