note
Tux
<p>That is not a reason to want to do it the way it is in your mind right now.</p>
<p>It is rather funny to see this topic, as it is almost exactly the problem that dragged me into perl development in the first place. I almost did the same, and once everything "worked", problems started to arise.</p>
<p>The solution, as others already stated in a more or less explicit way, is to make ONE (and only ONE) global (or at least in a scope as limited as possible) variable that contains all your hashes that you do not yet know about.</p>
<code>
my %all_my_hashes;
$all_my_hashes{$variable} = { valorC => "value03", valorD => "value04", };
print $all_my_hashes{$variable}, "\n";
# later you read ; records
while (<>) { # consider Text::CSV_XS with sep_char => ";"
my @alelos = split ";" => $_, -1;
while (@loci_codes) {
$variable = shift @loci_codes;
$all_my_hashes{$variable};
my $allele1 = shift @alelos;
my $allele2 = shift @alelos;
$all_my_hashes{$variable}{$allele1) += 1;
$all_my_hashes{$variable}{$allele2} += 1;
}
$all_my_hashes{Bet01} = { 230 => 2, 238 => 5, 224 => 1, };
$all_my_hashes{Bet05} = { 101 => 2, 103 => 2, 0 => 4, };
</code>
<p>Note that the main difference is that you'd need to initialize as anonymous hashes instead of lists, so</p>
<code>
%$foo = ( 1, 2, ... );
=>
my %all_my_hashes;
$all_my_hashes{$foo} = { 1 => 2, ... };
</code>
<p>Of course you can also use a ref as top-level, so the reference stands out better (for any value of better):</p>
<code>
my $all_my_hashes;
$all_my_hashes->{$foo} = { 1 => 2, ... };
</code>
<p>One *huge* advantage with using a scalar reference is that you can easily (and safe and fast) pass that reference around to other parts of your program and limit the scope.</p>
<p>Aut-vivivication is your friend!</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-200365">
<br />
Enjoy, Have FUN! H.Merijn
</div></div>
1007852
1007872