<?xml version="1.0" encoding="windows-1252"?>
<node id="1008288" title="better array to hash conversion" created="2012-12-11 07:18:09" updated="2012-12-11 07:18:09">
<type id="115">
perlquestion</type>
<author id="998701">
perltux</author>
<data>
<field name="doctext">
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.&lt;br&gt;
The following code does this, but I wonder if there is a more elegant and/or efficient way of doing this?&lt;br&gt;
(The content of the array could be anything, not necessarily the letter sequence I used in my example below)&lt;br&gt;
&lt;br&gt;
&lt;code&gt;my @array=qw(a b c d e f g h);
my %hash;
for (my $idx=0; $idx&lt;@array; $idx++) { $hash{$array[$idx]} = $idx; }&lt;/code&gt;
</field>
</data>
</node>
