
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 "Amount? ";
  my $amount = <>;
  chomp $amount;

  if ($amount == 0) {
    last;
  }

  my $match;
  for my $customer (sort keys %balance) {
    my $diff = ($balance{$customer} - $amount)/$amount;
    if ($diff <= 0.1 && $diff >= -0.1) { 
      printf "%12s %6.2f\n", $customer, $balance{$customer};
      $match = 1;
    }
  }
  unless ($match) {
    print "No matches.\n";
  }
}


