I have a hash of hashes
my %change;
while ( <DATA> ) {
chomp;
my ($gene, $condition, $change) = split;
$change{$gene}{$condition} = $change;
}
print Dumper \%change;
__DATA__
gene1 condition1 10
gene2 condition1 0.5
gene3 condition1 1.5
gene1 condition2 2
gene2 condition2 13.5
gene3 condition2 0.25
And I want to sort it by value:
gene2 condition2 13.5
gene1 condition1 10
gene1 condition2 2
gene3 condition1 1.5
gene2 condition1 0.5
gene3 condition2 0.25
I'm using:
for my $g (keys %change){
for my $con (keys $change{$g}){
for my $ch (sort { $change{$g}{$a} <=> $change{$g}{$b} } keys $change{$g}{$con} ) {
print "$g\t$con\t$ch\n";
}
}
}
But this doesn't work, and generates the error
Type of argument to keys on reference must be unblessed hashref or arrayref at untitled.pl line 23, line 6.
Line 23 is
for my $ch (sort { $change{$g}{$a} <=> $change{$g}{$b} } keys $change{$g}{$con}){
Can anyone point me in the right direction?