$VAR3 = 'URIBL_OB_SURBL+MPART_ALT_DIFF_COUNT'; $VAR4 = { 'Total' => 10, 'Value' => '3.716' }; #### $VAR5 = 'BAYES_00+FORGED_RCVD_HELO'; $VAR6 = { 'Total' => 5, 'Value' => '-2.464' }; $VAR7 = 'BAYES_00+HTML_LINK_PUSH_HERE'; $VAR8 = { 'Total' => 1, 'Value' => '-2.202' }; $VAR9 = 'SPF_HELO_PASS'; $VAR10 = { 'Total' => 16, 'Value' => '-0.001' }; $VAR11 = 'BAYES_95+HTML_MIME_NO_HTML_TAG'; $VAR12 = { 'Total' => 1, 'Value' => '4.082' }; #### if ($sort eq 't') { $sorter = sub { sort values %{ do { my %tosort; for my $test (keys %tests) { # Prints values correctly # Values go into hash correctly # print "Test: $test -- Total: ". $tests{$test}{"Total"} ."\n"; $tosort{$test} = $tests{$test}{"Total"}; } return \%tosort; }; } }; #### } elsif ($sort eq 'v') { $sorter = sub { sort values %{ sub { my %tosort; for my $test (keys %tests) { # Prints values correctly # Values go into hash correctly # print "Test: $test -- Total: ". $tests{$test}{"Value"} ."\n"; $tosort{$test} = $tests{$test}{"Value"}; } return \%tosort; }; } }; } else { $sorter = sub { sort keys %tests }; } #### while ( my ($test,$val) = each %{$sorter->()} ) { print "Test: ". $test Val: $val\n"; # Sorter value # Show me the assocaited %tests stuff print " Total: ". $tests{$test}{"Total"} ."\n"; print " Value: ". $tests{$test}{"Value"} ."\n\n"; } #### sub Print_Tests($$) { my $sort = shift || "a"; my $order = shift || "d"; my (@ordered_keys); # Create the sorter if (($sort eq 't') && ($order eq "a")) { @ordered_keys = sort { $tests{$a}{"Total"} <=> $tests{$b}{"Total"} } keys %tests; } elsif (($sort eq 't') && ($order eq "d")) { @ordered_keys = sort { $tests{$b}{"Total"} <=> $tests{$a}{"Total"} } keys %tests; } elsif (($sort eq 'v') && ($order eq "d")) { @ordered_keys = sort { $tests{$b}{"Value"} <=> $tests{$a}{"Value"} } keys %tests; } elsif (($sort eq 'v') && ($order eq "a")) { @ordered_keys = sort { $tests{$a}{"Value"} <=> $tests{$b}{"Value"} } keys %tests; } elsif (($sort eq 'a') && ($order eq "a")) { @ordered_keys = sort keys %tests; } else { @ordered_keys = sort reverse keys %tests; } foreach my $key (@ordered_keys) { my $val = $tests{$key}; print "$key\n"; print " Total: $val->{Total}\n"; print " Value: $val->{Value}\n\n"; } }