This should get you moving in a useful direction; it demonstrates the use of a Hash (which happens to also be a Hash Of Hashes (HoH), which you could research on your own).

CAVEAT: This is not production quality code. Its purpose is demonstration, not solution.

#!/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;

Results:

$ ./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


In reply to Re: Filter out an input file with a given waiver file, and output to a specific file by dbander
in thread Filter out an input file with a given waiver file, and output to a specific file by DespacitoPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.