
use strict 'vars';

unless (open DEP, "<", "deposits.txt") {
  die "Couldn't open 'deposits.txt' for reading: $!; aborting";
}
my %balance;
while (<DEP>) {
  chomp;
  my ($who, $action, $amount) = split;
  if    ($action eq 'deposit')  { $balance{$who} += $amount }
  elsif ($action eq 'withdraw') { $balance{$who} -= $amount }
  else { die "Unknown action '$action'" }
}

while (1) {
  print "Customer? ";
  my $who = <>;
  chomp $who;
  if ($who eq "") {
    last;
  }
  if (defined $balance{$who}) {
    print "Balance for $who is $balance{$who}\n";
  } else {
    print "There is no bank customer named '$who'.\n";
  }
}


