I have several text files ( A.txtand B.txt) that look like this (can have ~ 10,000 lines each)
processa,id1=123,id2=5321
processa,id1=432,id2=3721
processa,id1=3,id2=521
processb,id1=9822,id2=521
processa,id1=213,id2=1
processc,id1=822,id2=521
I need to check if every line in the file A.txtis present in B.txt( B.txtalso, this is normal).
The fact is that lines can be in any order in two files, so I think that I will sort them in a certain order in both files in O(nlogn), and then match each line in A.txtwith the next line in B.txtin O(n). I can implement the hash, but the files are large, and this comparison happens only once, after which these files are restored, so I do not think this is a good idea.
What is the best way to sort files in Perl? Any orders will be made, it just has to be ordering.
For example, when ordering in a dictionary, it will be
processa,id1=123,id2=5321
processa,id1=213,id2=1
processa,id1=3,id2=521
processa,id1=432,id2=3721
processb,id1=9822,id2=521
processc,id1=822,id2=521
As I mentioned earlier, any ordering will be just as fine if Perl quickly does this.
I want to do this from inside Perl code, after opening the file like this
open (FH, "<A.txt");
Any comments, ideas, etc. will be helpful.