Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Last active December 18, 2015 02:39
Show Gist options
  • Save jreisinger/5713082 to your computer and use it in GitHub Desktop.
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/.
#!/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