use strict;
use warnings;
my %hoh_test = (
foo1 => { bar => -0.12697, baz => -0.000398154, },
foo2 => { bar => -4.0183e-05, baz => 0, },
foo3 => { bar => 9.966003977e-06, baz => 0.0001939, },
);
# Sort on $foo decending
foreach my $foo ( sort { $b cmp $a } keys %hoh_test ) {
# Sort on values decending
foreach my $ba (
sort { $hoh_test{$foo}{$b} <=> $hoh_test{$foo}{$a} }
keys %{$hoh_test{$foo}}
) {
printf "foo: %s, ba: %s, value: %s\n",
$foo,
$ba,
$hoh_test{$foo}{$ba};
}
}
####
use strict;
use warnings;
my %hoh_test = (
foo1 => { bar => -0.12697, baz => -0.000398154, },
foo2 => { bar => -4.0183e-05, baz => 0, },
foo3 => { bar => 9.966003977e-06, baz => 0.0001939, },
);
# Sort on $foo decending
foreach my $foo ( sort { $b cmp $a } keys %hoh_test ) {
# Sort on $ba decending
foreach my $ba ( sort { $b cmp $a } keys %{$hoh_test{$foo}} ) {
printf "foo: %s, ba: %s, value: %s\n",
$foo,
$ba,
$hoh_test{$foo}{$ba};
}
}
##
##
use strict;
use warnings;
use utf8;
my %hoh_test = (
foo1 => { bar => -0.12697, baz => -0.000398154, },
foo2 => { bar => -4.0183e-05, baz => 0, },
foo3 => { bar => 9.966003977e-06, baz => 0.0001939, },
);
# Sort on values by pushing into an intermediary structure
my @ordering;
foreach my $foo ( keys %hoh_test ) {
foreach my $ba ( keys %{ $hoh_test{$foo} } ) {
push @ordering, { foo => $foo, ba => $ba, v => $hoh_test{$foo}{$ba}, };
}
}
# Sort intermediary structure on value (v) from above.
foreach my $i ( sort { $ordering[$b]{v} <=> $ordering[$a]{v} } 0 .. $#ordering ) {
printf "foo: %s, ba: %s, value: %s\n",
$ordering[$i]{foo},
$ordering[$i]{ba},
$ordering[$i]{v};
}