Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - Perl

Status
Not open for further replies.

fabster01

MIS
Sep 3, 2003
3
US
Hi I am a newbie and I am stuck!

I need to read 2 files. Say file A and file B.

while reading file A, i also need to open file B and search the entire file for a specific keyword and then update file C.

For example, when reading file A, I identify a keyword "apple" then I open and search file B for all types of apple in file B (example, "green apple" and "red apple"), next I update file C. Then the program continue to read file A for the next keyword and found say "melon" and then open file B and do the search again and update file C. I was trying a while within a while loop but looks like it should not be done that way. Any other way??
 
That is fine if you are a newbie, but you need to have a basic understanding of perl and preferrably attempt some type of code before posting a thread. Without some attempt, people might think that you just want them to write a script for them without you having to do anything. I for one don't do that unless I am being paid for it. Even if someone is kind enough to just write something for you, you still need a basic understanding of perl or else you will not understand the script of how to modify it if necessary.

Here are some of the things you need to know to do this task. How to open and read files. How to open and write to files. Conditional statements. If statements. Regular Expressions.

Here is some pseudo code that shows the basic logic of what you are trying to do. Take this advice and see if you can make something of it then post back here again.

open file A
while (<FILE A>) {
if (/$keyword/) {
open file B
while ($line = <FILE B>) {
if (/$keyword/) {
open FILE C
print FILE C $line
}
}
}
}

That should be more than plenty to get you started. If you are totally lost by this, then you need to go back to your books and do some more studying before you attempt this.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top