#!/usr/bin/perl -w
#####################
#
# Sep 30 assignment
#
# Read the file input_for_sep30.txt
# and print a summary of the results.
#
# Exercise 1, section 6.6, pg 120 of our text.
#
# - Jim M. 
#
######################
use strict;

# Open the file for reading.
my $filename = "input_for_sep30.txt";
open(INPUT, $filename) or die "Oops - couldn't open '$filename' : $!";

# Declare a hash where we can put our data.
# It'll have keys = names, values = numbers (running total from file values)
#   %data = (
#                jim   => 22,
#                mary  => 31
#            );
my %data;

# Process each line in the file.
while (my $line = <INPUT>){
  chomp($line);
  my ($name, $number) = split /:/, $line;
  $data{$name} += $number;
}

# Print the report.
for my $person (sort keys %data){
  print "User:  $person\n";
  print "Total: $data{$person}\n\n";
}

# That's all...
