Instead of merging two files, there will now be 3 .txt files with the ending filename letters of L, H & A.

There is only 1 field in each list, consisting of an alpha/numberic ID (which may contain a '/' forward slash in some of the ID's).

List xxxL.txt is the 'Master List' to be fully retained in the output.

If there is an identical matching ID in either of the other two lists (yyyH.txt and zzzA.txt), then to flag list the total output of list xxxL.txt with a trailing space and either H (or) A depending on which list the ID from list xxxL.txt might match.

In some cases there will be NO match from yyyH.txt or zzzA.txt, so those list xxxL.txt ID's will NOT be flagged, but must remain on the output list.

Example/Sample:

(List) L entries:

ABC123 DEF456 GHI/789 JIK00/3P L357

(List) H entries

DEF456 GHI/789

(List) A entry

JIK00/3P

So the desire output .txt file would be:

ABC123 DEF456 H GHI789 H JIK00/3P A L357

If possible, the ultimate would be to add 3 lines at the end of the output .txt file with a total count summary like:

L = 5 <-- The Total ID's in List L H = 2 <-- The Total ID's flagged from list H A = 1 <-- The Total ID's flagged from list A

This would eliminate having to import the final output file into Excel and do 2 sorts to tally up the H and A flags (and to double-check that all entries from 'Master List' L are included).

Thanks for your efforts and reply, Bill. I had been wondering about a Hash as I ran across something called List:Compare and my eyeballs started rolling.

I added the Shebang to your script and ran it.

The entire xxxL.txt file outputs as intended, but found a few odd things.

1. Viewing via Command Prompt, there were no (space) H or (space) A flags ... only several characters which were not ID's appeared following multiple (spaces) for about 3 out the 2,845 entries on the xxxL.txt list.

2. I viewed then viewed the list via NotePad and got the same results.

3. So I decided to try and import the file into Excel, and each entry on the list had a weird "Box" with a "?" inside of it. I tried each delimiter option for importing, but got the same result... except choosing the "Tab" delimiter got rid of the box with the ? inside and the all the ID numbers were accurate (but without any "H" or "A" flags.

The script ran without any hangups or warnings, so not sure what to do.

Still plodding away and tried a script for another task here using a Hash that had some issues - like the output contained a lot of random blank lines. But it was worth a try to run the L and H lists, and then take that result and run it with the A list (changing xxxL to xxxL2 in the code) ... in spite of their being the previous "Reverse" stuff involved.

Importing the result into Excel and group deleting the blank lines netted the original 2,845 xxxL list ID's which was good. And both {space} H and {space} A flags showed up adjacent to a number of entries. What I do NOT know is how accurate this all turned out unless I manually compare all 3 lists (2,845 + 735 + 699 entries). Ugh ;-(

How to re-tweak the code to nuke the "Reverse" stuff and use all 3 lists at once has me baffled, however at least there seems to now be some proverbial "light at the end of the tunnel."

your while loop isn't doing anything useful. You first initialize the @fields array to an empty array and then use this empty array as a key to your array.

Also, this:

Code

my ( $listL, $listH, $listA, %hash ) = @ARGV;

looks strange to me. I your imagine that the first three arguments are the names of the L, H and A files, but then you don't use them. But, more importantly, I fail to see how you expect to populate a hash from the command line argument.

To me, given what you explained in the OP, you want to read the A and the H files and store their contents in two hashes, then close these two files (that you non longer need, and then read the L file line by line and, for each line, check if it is found in the two hashes, and populate the output accordingly.

You can't really use something lile:

Code

while (<>) { # ...

because you need to distinguish between the various files. So you need to open each file separately.

You haven't shown your data, but since you called one of your original variables $letter, I assume that you are not dealing with numbers, but with alphanumerical data. In this case, the "==" operator is not what you need (this is only for comparing numbers), try the "eq" operator instead.

Otherwise, I was going to provide some code, but figured out it would not be sunstantially different from Bill's proposal. I would therefore suggest that you state in which respect the code supplied by Bill does not fit your purpose, so that a change to his code may be proposed.

You haven't shown your data, but since you called one of your original variables $letter, I assume that you are not dealing with numbers, but with alphanumerical data. In this case, the "==" operator is not what you need (this is only for comparing numbers), try the "eq" operator instead.

Otherwise, I was going to provide some code, but figured out it would not be sunstantially different from Bill's proposal. I would therefore suggest that you state in which respect the code supplied by Bill does not fit your purpose, so that a change to his code may be proposed.

I further edited the 2 lines above, and have spent hours trying different attempts to match the H & A ID's to any on the L list without success.

As earlier indicated, Bill's code works to read all the data files in, but the problem is none of the H or A flags show up in the final output.

I also tried two foreach loops within the while loop - one for H and one for A but nil.

Yes, the ID's are (as initially stated), alpha-numeric BUT may contain a "/" forward slash as also indicated earlier.

At this point I will manually pre-sort each of the lists BEFORE running the script to keep things as simple as possible trying to figure how HOW ON EARTH to match any ID's on the H and/or A list to the L list.

I have been scouring various Tutorial examples looking for ANYTHING that might be a solution to the non-printing and found this:

Code

Checking for Existence

If you try to access a key/value pair from a hash that doesn't exist, you'll normally get the undefined value, and if you have warnings switched on, then you'll get a warning generated at run time. You can get around this by using the exists function, which returns true if the named key exists, irrespective of what its value might be:

The problem has almost certainly to do with your input data files which are not exactly what you think. First my test with your data:

Code

$ perl test_l_h.pl ABC123 DEF456 H GHI/789 H JIK00/3P A L357

As you can see it works fine for me.

The first time I ran it, however, it worked only for one of the lines (DEF456 H), not the two others. I then figured out that the other two had a trailing white space, so that the L line could not be found in the hash. I added some code to remove trailing white spaces, and then it worked OK. The code below is the same as what I posted yesterday, except that I added code lines to remove trailing white spaces and to remove Windows carriage returns ("\r" character), just in case your files were prepared on Windows and your test running on Linux or Unix. And, as you saw above, it works according to expectations.

is never going to be executed because the condition will never be true, because $_ contains one line of your file and $L_list is a file handler (i.e. something like a pointer to your file) and they never going to be equal.

I got back up out of bed on 3 hours of sleep to start combing through more Perl documentation on Hashes to see if I could find a solution.

But first I checked this thread and WOW ... Thank You...I learned many things from your posting, and hope some of the other thread readers have too !!!

Thank you for your persistence and tenacity to help me with with this matter (and the revised code). Your explanations were VERY educational.

Part of the problem was, in fact, yes ... that the actual working lists (H, A, L) here were exported from WinDOZE Excel files. It never crossed my mind about trailing 'junk' spaces being part of the problem ;-(

So I decided to be 'Bold' and added 2 more lists (F, N) to your code and cloned the Summary Total lines before running it. After the days & hours of frustrating "dead-ends", it was a thrilling relief to see this work (and then separately created a >zsummary.txt file) !!!

I have named the script 'billandlaurent.pl' :^) :^)

This will be used to compare other 'listL.txt' source files to H, A, F & N files which will be periodically updated, and also save a great deal of time in the future.

Thank you so much again !!!

- stuckinarut (But no longer in this matter)

P.S. Actual list file counts used here:

L = 2,845 H = 694 A = 735 F = 980 N = 710

Code

use strict; use warnings; my %H_list;

# ============================================================== # Special thanks to BillKSmith and Laurent_R at www.perlguru.com # for the code that works and tremendous educational experience! # ==============================================================

I am happy that you are out of trouble and that I was able to help you.

It is a pleasure to help someone (like you) who is really trying hard to do the things, rather than simply asking for help and lazily waiting for a ready-made solution to fall from the sky. I do not know if you intend to develop more programs, but if you do, I am sure you will quickly make giant progresses.