#!/usr/bin/perl use strict; use warnings; # Set up a hash to receive the information my %violationdata = (); # Read the violations file into the hash open my $violations, '<', 'violations.txt' or die; while (my $vline = <$violations>) { my ($vkey, $ukey, $credit, $debit, $balance, $notes) = split /\s+/, $vline; $violationdata{$vkey}{UKEY} = $ukey; $violationdata{$vkey}{CREDIT} = $credit; $violationdata{$vkey}{DEBIT} = $debit; $violationdata{$vkey}{BALANCE} = $balance; $violationdata{$vkey}{NOTES} = $notes; } close $violations; # Display the contents of the hash foreach my $okey (sort keys %violationdata) { print " $okey:\n"; foreach my $skey (sort keys %{$violationdata{$okey}}) { my $sval = $violationdata{$okey}{$skey}; print " $skey: $sval\n"; } } # Now process the waivers and update the hash open my $waivers, '<', 'waivers.txt' or die; close $waivers; # Now write out the hash to the updated violations file open my $updated, '>', 'updated.txt' or die; close $updated; #### $ ./violwaiv.pl abcd123: BALANCE: -900.00 CREDIT: 100.00 DEBIT: 1000.00 NOTES: (VIOLATED) UKEY: klmn123 abcd124: BALANCE: -900.00 CREDIT: 100.00 DEBIT: 1000.00 NOTES: (VIOLATED) UKEY: klmn124