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?


True laziness is hard work

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.