Last active
December 18, 2015 02:39
-
-
Save jreisinger/5713082 to your computer and use it in GitHub Desktop.
Typical data reduction using references. Get input file (coconet.dat) from http://www.intermediateperl.com/downloads_page/.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
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 @destinations = | |
sort { $total_bytes{$src}{$b} <=> $total_bytes{$src}{$a} } | |
keys %{ $total_bytes{$src} }; | |
print "$src sent $total_bytes{$src}{$all} total bytes\n"; | |
for my $dst (@destinations) { | |
next if $dst eq $all; | |
print "\t=> $dst: $total_bytes{$src}{$dst} bytes\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment