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; }
|
---|
In Section
Seekers of Perl Wisdom