I have three text files containing names and grades. I removed the grades and created new files with just the names. Here is what the files look like:
first.txt
Alice
Bob
Carl
Derrick
Jessica
Sarah
Zach
second.txt
Alice
Bob
Derrick
Jared
Jessica
Sarah
Zach
third.txt
Bob
Jared
Sarah
Slate
Terry
Zach
I want to compare all three files and if there is a name in one file that is not in the other, I want to add it in. So at the end all files will contain the same names. I know you gonna add lines in perl, so a new file will have to created to do this.
Here is my approach to it. I start by comparing the first and second, adding differences from second into first. Then comparing first and second, adding differences from first into second. Then I compare the second file (either works) with third file, print differences from second into third file. Then I compare second and third, and print differences that are in third into both first and second. I put compare statements in as well to ensure the files have the same entries.
The files with grades are named original1.txt original2.txt original3.txt
In the end I will take the files containing the new names, and combine them with the files that have the grades. If there is no grade for a new name in the file, it will simply have no grade entry.
Is there a cleaner way of doing this? It looks like a huge mess.
sort -um first.txt second.txt third.txtwill give all the names from all the files. (If not already sorted, drop the-m). Thenjoinfor combining with the grade files... - Shawnuse strict; use warnings;Use proper indentation. Move repeated code fragments intosubs. - Robert