Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Search and delete lines based on string matching

by ptum (Priest)
on Mar 13, 2007 at 14:00 UTC ( [id://604532]=note: print w/replies, xml ) Need Help??


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.

  • Comment on Re: Search and delete lines based on string matching

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://604532]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found