my %provisions;
my $person;
while (<>) {
if (/^(\S.*)/) { # a person's name (no leading whitespace)
$person = $1;
} elsif (/^\s+(\S.*)/) { # a provision
die 'No person yet!' unless defined $person;
push @{ $provisions{$person} }, $1;
} else {
die "I don't understand: $_";
}
}
####
my %total_bytes;
while (<>) {
my ($source, $destination, $bytes) = split;
$total_bytes{$source}{$destination} += $bytes;
}
for my $source (sort keys %total_bytes) {
for my $destination (sort keys %{ $total_bytes{$source} }) {
print "$source => $destination:",
" $total_bytes{$source}{$destination} bytes\n";
}
print "\n";
}
##
##
The Skipper
blue_shirt
hat
jacket
preserver
sunscreen
Professor
sunscreen
water_bottle
slide_rule
Gilligan
red_shirt
hat
lucky_socks
water_bottle
The Skipper
sextant
##
##
professor.hut skipper.crew.hut 8655
ginger.girl.hut laser3.copyroom.hut 6404
skipper.crew.hut fileserver.copyroom.hut 8534
gilligan.crew.hut skipper.crew.hut 1004
laser3.copyroom.hut ginger.girl.hut 4366
maryann.girl.hut professor.hut 8454
skipper.crew.hut professor.hut 7475
gilligan.crew.hut maryann.girl.hut 8128
gilligan.crew.hut maryann.girl.hut 5277
gilligan.crew.hut fileserver.copyroom.hut 6117
skipper.crew.hut professor.hut 5101
gilligan.crew.hut gilligan.crew.hut 9973
ginger.girl.hut fileserver.copyroom.hut 1448
skipper.crew.hut gilligan.crew.hut 2146
fileserver.copyroom.hut gilligan.crew.hut 9568
maryann.girl.hut laser3.copyroom.hut 8024
fileserver.copyroom.hut laser3.copyroom.hut 9574