我想从散列的散列中获取价值,但我没有。我的代码是:
sub test {
my $filename = $_[0];
open INFILE, ${filename} or die $!;
my %hashCount;
my @firstline = split('\t',<INFILE>);
shift(@firstline);
while (my $line = <INFILE>)
{
my %temp;
chomp($line);
my @line = split('\t', $line);
foreach my $cpt (1..$#line) {
$temp{$firstline[$cpt-1]}=$line[$cpt];
}
$hashCount{$line[0]}={%temp};
}
return %hashCount;
}
sub get_hash_of_hash {
my $h = shift;
foreach my $key (keys %$h) {
if( ref $h->{$key}) {
get_hash_of_hash( $h->{$key} );
}
else {
say $h->{$key};
}
}
}
当我显示我的哈希时:
$VAR10679 = 'M00967_43_1106_2493_14707';
$VAR10680 = {
'A' => '1',
'B' => '0',
'C' => '1',
'D' => '0',
'E' => '0'
};
我的第一个函数返回我的哈希值,我用第二个函数得到我的特定值。所以我想获得这样的价值:
my %hashTest = test("FILE.txt");
get_hash_of_hash(%hashTest,"M00967_43_1106_2493_14707","A")
//return value '1'