I'm trying to sort by the 'cnt' value in the sock_total hash, but can't figure out how to do it when I don't know what the $rip and $pid values are till I'm in the loop.
I managed to do this before on a HOH where I knew the outer keys, but in this case Im working my way through all values and want to show the most active sockets by count first.
I've done sorts before but having trouble figuring out how to do the same with the nested hash this round:
example of a previous sort:
foreach $sym (sort {$pid_PFAULT{$pid}{$b} <=> $pid_PFAULT{$pid}
+{$a}} (keys %{$pid_PFAULT{$pid}}))
(and the above required I be inside a loop knowing the $pid value)
Current problem HOH I need to sort:
# text report by remoteIP:port
sub text_sock_report_byrip()
{
my $pid, my $avg, my $rip, my $type, my $cmd;
for $rip (keys %sock_total) {
print "Report on remote host: $rip\n";
for $pid (keys %{$sock_total{$rip}}) {
printf("pid: %s\n",$pid);
for $type (keys %{$sock_total{$rip}{$pid}}) {
printf("\t%s, ",$type);
printf("\tcnt: %8d,
",$sock_total{$rip}{$pid}{$type}{'cnt'});
$avg = $sock_total{$rip}{$pid}{$type}{'tot'}
/ $sock_total{$rip}{$pid}{$type}{'cnt'};
printf("\tavg: %12.6f, ",$avg);
printf("\tmin: %12.6f,
",$sock_total{$rip}{$pid}{$type}{'min'});
printf("\tmax:
%12.6f\n",$sock_total{$rip}{$pid}{$type}{'max'});
}
}
}
}
Sample data: (where VAR1=$rip, VAR2=$pid 'cnt' => 1)
('cnt' is integer from 1>n)
VAR1 = 'R=10.10.0.111:54998';
$VAR2 = {
'12913' => {
'write' => {
'tot' => '2.3e-05',
'min' => '0.000023',
'max' => '0.000023',
'cnt' => 1
}
}
};
$VAR3 = 'R=10.10.1.110:57354';
$VAR4 = {
'12913' => {
'read' => {
'tot' => '1.5e-05',
..... etc....
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.