Chinaunix首页 | 论坛 | 博客
  • 博客访问: 492457
  • 博文数量: 138
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 716
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-03 21:48
文章分类

全部博文(138)

文章存档

2019年(1)

2017年(5)

2016年(99)

2015年(33)

我的朋友

分类: PERL

2017-03-23 00:19:15


点击(此处)折叠或打开

  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;

阅读(1078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~