点击(此处)折叠或打开
- #!/usr/bin/perl
- use strict;
- use warnings;
- #5-2 count net bytes
- use Data::Dumper;
- my $all = "***all_machines***";
- my %total_bytes;
- while(<>){
- next if /^#/;
- my ($src, $dst, $bytes) = split;
- $total_bytes{$src}{$dst} += $bytes;
- $total_bytes{$src}{$all} += $bytes;
- }
- my @sources = sort {$total_bytes{$b}{$all} <=> $total_bytes{$a}{$all} } keys %total_bytes;
- for my $src (@sources){
- my @destination = sort { $total_bytes{$src}{$b} <=> $total_bytes{$src}{$a} } keys %total_bytes;
- print "$src: $total_bytes{$src}{$all} total bytes sent! \n";
- for my $dst (@destination){
-
- next if $dst eq $all ;
- print "$src => $dst: ", "$total_bytes{$src}{$dst} bytes!\n";
- }
-
- print "\n";
- }
- print Dumper \%total_bytes;