<?xml version="1.0" encoding="windows-1252"?>
<node id="1007856" title="Re^2: variable as hash name" created="2012-12-08 00:19:55" updated="2012-12-08 00:19:55">
<type id="11">
note</type>
<author id="1007849">
blackzero</author>
<data>
<field name="doctext">
&lt;p&gt;Thank you, Dave.

Now, the point is that I'm reading an external file in the following format:&lt;/p&gt;

&lt;code&gt;
230;238;101;103;138;146;112;116;;
230;238;101;103;146;146;108;112;;
224;238;0;0;146;146;110;118;;
238;238;0;0;146;146;112;114;;
&lt;/code&gt;

&lt;p&gt;I have an array named @loci_codes with this content:&lt;/p&gt;
&lt;code&gt;
@loci_codes = qw( Bet01 Bet05 Bet06 Bet12 );
&lt;/code&gt;

&lt;p&gt;What I want is to read each line ( &lt;&gt; ), split and put the elements in an array &lt;/p&gt;
&lt;code&gt;
while ( defined( $line = &lt;&gt; ) )
my @alelos = split ";", $line;
&lt;/code&gt;

&lt;p&gt;Than I want to take the elements of @alelos two by two and put each pair in a different hash. The PROBLEM is that I want each of these hashes to be named after on of the elements of @loci_codes. &lt;/p&gt;

&lt;code&gt; 
while ( @loci_codes )
{
  $variable = shift @loci_codes;
  %$variable;
  $allele1 = shift @alelos;
  $allele2 = shift @alelos;
  %$variable{$allele1) += 1;
  %$variable{$allele2} += 1;
}
&lt;/code&gt; 

&lt;p&gt;And doing that for each line of the input, I want to have a hash named after a element of @loci_codes and populated with these pairs.&lt;/p&gt;

&lt;p&gt;EXAMPLE:&lt;/p&gt;
&lt;code&gt;
%Bet01 = ( 230 =&gt; 2, 238 =&gt; 5, 224 =&gt; 1,);
%Bet05 = ( 101 =&gt; 2, 103 =&gt; 2, 0 =&gt; 4, );
...
&lt;/code&gt;

&lt;p&gt; NOTE: The content of @loci_codes may change according to the input file readed. THATS why I cant use static names for the hashes. &lt;/p&gt;</field>
<field name="root_node">
1007852</field>
<field name="parent_node">
1007854</field>
</data>
</node>
