note
Anonymous Monk
<p>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:</p>
<code>
$hash{ $array[$_] } = $_ for (0..$#array);
</code>
<p>And something that works only after 5.12 but is very easy to read:</p>
<code>
use 5.012;
while (my ($idx, $val) = each(@array)) {
$hash{$val} = $idx;
}
</code>
1008288
1008288
3