http://qs321.pair.com?node_id=604532


in reply to Search and delete lines based on string matching

Since you posted as Anonymonk, you can't go back and edit your post, but next time, please use

<code>
tags.

What error are you seeing? You didn't tell us.

Is this a homework problem? We don't mind helping, but we're not particularly inclined to do your homework.

To solve a problem like this, I would generally read in the contents of file A into a hash, since you just want to use those words as a lookup. Then I would open files B and C, step through the contents of file B a line at a time, and, whenever the line of B contains a word in my hash, drop it on the floor -- otherwise, write that line to file C. I don't think that opening the file handles inside your loop is a good idea.

You're not really clear as to whether file B contains single words or longer strings -- if longer strings, then you might want to split the line into individual tokens (which can then be individually compared to your hash from file A) or (if the number of words in file A is small enough) you may prefer to build a regular expression by which you evaluate each string. A little more detail might help us to help you more effectively.