#!/usr/bin/perl
###########
#
# in class version of sep30.pl
#
###############
use strict;

# open a file

my $filename = "input_for_sep30.txt";
open(INPUT, $filename) or die "OOPS - couldn't open '$filename' : $!";

# loop over the lines in file
# read each one, extract name and number
# add number to previous tally

# Here's where we'll put the name => number data.
my %data;

while (my $line = <INPUT>){
  chomp($line);
  # print " line = '$line' \n";

  my ($name, $number) = split /:/, $line;
  # print " name:'$name', number:'$number' \n";

  # $data{$name} = $data{$name} + $number;
  $data{$name} += $number;

}

# loop over the hash, print out the values.
for my $name (sort keys %data){
 print "User:  $name\n";
 print "Total: $data{$name}\n\n";
}



