foreach my $summary (@cmdoutput) { chomp($summary); $summary =~ s/\s+/ /g; my $Intf = $IHQ = $IQD = $OHQ = $OQD = $RXBS = $RXPS = $TXBS = $TXPS = $TRTL = $Track = 0; select STDOUT; # remove extra spaces my $fields = () = $summary =~ /[\s+,:]/g; # Debug if records are not processing correctly # print "Record contains $fields fields\n"; if ($fields == 0) { print "No fields\n"; next; } elsif ($fields == 10) { ($Star,$Intf,$IHQ,$IQD,$OHQ,$OQD,$RXBS,$RXPS,$TXBS,$TXPS,$TRTL) = split(' ', $summary); if ($IHQ eq "-") { next;} elsif ($Intf eq "Interface") {next;} else { $Track = join "<<-", $rec,$Intf; $interface_bytes{$Track} += $RXBS; $Track = join "->>", $rec,$Intf; $interface_bytes{$Track} += $TXBS; } } } # my $key = ""; my @keys = (); my $lastid = 4; # sort by value and put the keys in an array (Ascending sort) @keys = sort {$interface_bytes{$a} <=> $interface_bytes{b}} keys %interface_bytes; foreach $key (@keys[0..$lastid]) { if (not defined $key) {next;} # printf("%-45s %-6d\n","\t".$key,$interface_bytes{$key}); # my $number = $interface_bytes{$key}; # $number =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; # printf("%-20s %-8s\n",$key,$number); printf("%-10s %-6s\n","\t".$key,$interface_bytes{$key}); }