Pathologically Eclectic Rubbish Lister  
PerlMonks 
Comment on 
( #3333=superdoc: print w/ replies, xml )  Need Help?? 
You basically want to calculate the intersection of two lists (and the negation of that). The following algorithm will work, assuming relatively small lists and unsorted initial input:
The more general algorithm, above, runs at nearlinear time but will consume memory proportional to the number of elements in your DEL list (which is still much better than your solution, which rereads the entire DEL list for each line of the ORG list!) Less general option: If your initial files are known to be presorted by your key value, you can traverse each with a pair of list cursors. The advantage of this approach is that it runs in strict linear time on the total number of elements across both lists, and uses a small constant amount of memory (i.e., memory does not increase with the size of the DEL list.) You might also want to look at List::Compare (specifically, the intersection method) for a reusable solution if your data is small enough where storing both sets in RAM isn't an issue. Have fun! In reply to Re: Search and Remove
by rjt

