Hello all,
I have a tab delimited file that contains (orig_accts.txt) 7 columns. I have another file (accts_to_exclude) which I want to compare against orig_accts¡Kand only output to a file what exists in orig_accts (but NOT in accts_to_exclude). I am currently doing this using a hash with following code.
$excludeaccts = "accts_to_exclude.txt";
Open(FILEHANDLE, $excludeaccts) || die ("Cannot open $excludeaccts");
%lookup = map {chomp; $_ => undef} <FILEHANDLE>;
close(FILEHANDLE);
$origlist = "orig_accts.txt";
open(ACCTLISTFILE, $origlist) || die ("Cannot open orig_accts.txt");
open($output, '>', 'output.txt') || die ("Cannot open output file outp
+ut.txt");
while ($line = <ACCTLISTFILE>){
chomp $line;
($filename, $state, $amt, $ttl, $account, $name, $invnum) = split /\
+t/, $line;
next if exists $lookup{$account};
print $output "$filename $state $amt $ttl $account $name $invnum\n";
}
Now, I want to check this output file against more lists
List1.txt (contains a list of accounts)
List2.txt (contains a diff list of accounts)
List3.txt (contains a list of names)
Check each account (from output.txt) against account in List1.txt and if it exists, do something (write this info to file1) and go on to checking the next account, and so on.
If the account does not exist in List1.txt, go on to checking for it in List2.txt. If it does exist in List2.txt, write this information into file2¡K.and continue checking the list
If the accounts does not exist in List2.txt, check for the name against the name in List3.txt, and if it exists, write it to file2.
Everything that remains should be written to file1
I'm not sure how to add this logic to the above code. I think it's possible to have more hashes but it doesn¡¦t seem very efficient. Any help is greatly appreciated.
Thank you.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.