#!/usr/bin/perl use strict; use warnings; use diagnostics; my ( $from, $to, $hh, $mm, $bytes ) = (); my %from_to_bytes = (); while () { ( $from, $to, $hh, $mm, $bytes ) = /^(\S+) (\S+) (\d+):(\d+) (\d+)$/ or ( warn "bad format on line $.: $_" ), next; $from_to_bytes{$from}{$to} += $bytes; } my %to_hosts = (); for my $from ( sort keys %from_to_bytes ) { my $second = $from_to_bytes{$from}; my @keys = keys %$second; @to_hosts{@keys} = (); } my @to_hosts = sort keys %to_hosts; printf "%10s:", "bytes to"; for (@to_hosts) { printf " %10s", $_; } print "\n"; my $total = (); for my $from ( sort keys %from_to_bytes ) { printf "%10s:", $from; for my $to (@to_hosts) { my $bytes = $from_to_bytes{$from}{$to} || "- none -"; printf " %10s", $bytes; { no warnings; $total += $bytes; } # Calculate total row } printf " %5s", "$total"; $total = 0; # otherwise totalrow accumulates print "\n"; } for my $to (sort keys %from_to_bytes){ printf "%10s", "$from_to_bytes{$to}"; } __DATA__ barney barney 08:24 91 fred wilma 05:51 92 fred fred 11:20 83 fred wilma 11:07 76 wilma fred 22:07 3 barney barney 13:22 93 fred fred 06:52 95 fred wilma 17:21 92 barney barney 07:35 95 barney fred 09:58 14 betty barney 12:34 59 wilma barney 09:59 18 betty betty 22:44 29 wilma betty 07:39 99 wilma fred 14:30 91 betty barney 01:54 95 wilma fred 15:45 2