Actually I don't see you getting a 'top 10' of anything anywhere in that code. If I understand your problem I'd solve it something like:
#!/usr/bin/perl use strict; use warnings; my %hostsData = ( 'blah1' => [132, 208, 146, 53, 77, 295, 33, 205, 8, 167, 147, 6, 8 +7, 261, 158], 'blah2' => [40, 220, 222, 182, 276, 17, 128, 126, 102, 228, 247, 1 +69, 86, 182, 229], 'blah3' => [223, 175, 248, 285, 13, 235, 242, 187, 48, 40, 96, 114 +, 293, 133, 20], 'blah4' => [83, 125, 46, 170, 208, 292, 116, 49, 2, 246, 73, 65, 1 +80, 265, 48], 'blah5' => [59, 73, 256, 174, 235, 114, 136, 217, 204, 98, 278, 22 +1, 78, 287, 42], ); my %top10s; for my $host (keys %hostsData) { # Generate list of top 10 items for a host $top10s{$host} = [@{[reverse sort {$a <=> $b} @{$hostsData{$host} +}]}[0 .. 9]]; } my @top10; for (1 .. 10) { # Pick next top item my $topHost; my $topValue; for my $host (keys %top10s) { next if ! @{$top10s{$host}}; next if defined $topHost && $topValue >= $top10s{$host}[0]; $topHost = $host; $topValue = $top10s{$host}[0]; } last if ! defined $topHost; push @top10, [$topHost, $topValue]; shift @{$top10s{$topHost}}; } print "$_->[0]: $_->[1]\n" for @top10;
Prints:
blah1: 295 blah3: 293 blah4: 292 blah5: 287 blah3: 285 blah5: 278 blah2: 276 blah4: 265 blah1: 261 blah5: 256
If that isn't what you were looking for how about you write a sample script that doesn't need web or database access to demonstrate your problem and resubmit your question?
In reply to Re: How do I sort top 10 for multiple hosts?
by GrandFather
in thread How do I sort top 10 for multiple hosts?
by kdmurphy001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |