点击(此处)折叠或打开

  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;

  4. #5-2 count net bytes

  5. use Data::Dumper;

  6. my $all = "***all_machines***";
  7. my %total_bytes;
  8. while(<>){
  9.     next if /^#/;
  10.     my ($src, $dst, $bytes) = split;
  11.     $total_bytes{$src}{$dst} += $bytes;
  12.     $total_bytes{$src}{$all} += $bytes;
  13. }

  14. my @sources = sort {$total_bytes{$b}{$all} <=> $total_bytes{$a}{$all} } keys %total_bytes;

  15. for my $src (@sources){
  16.     my @destination = sort { $total_bytes{$src}{$b} <=> $total_bytes{$src}{$a} } keys %total_bytes;

  17.     print "$src: $total_bytes{$src}{$all} total bytes sent! \n";
  18.     for my $dst (@destination){
  19.         
  20.         next if $dst eq $all ;
  21.         print "$src => $dst: ", "$total_bytes{$src}{$dst} bytes!\n";
  22.     }
  23.     
  24.     print "\n";
  25. }


  26. print Dumper \%total_bytes;

09-10 04:32