perl_new2011 has asked for the wisdom of the Perl Monks concerning the following question:

Hello experts, I am relatively new in perl (1 month) and have come up with the following problem. I sincerely hope I will get some direction from this forum. I have two text files. File 1 content look like
ABCDEFG0098GHT J19.17 ABCDEFG0141314 J19.1 ABCDEFGQQ76890 WOK2234 ABCDEFG0Y56421 POK1 ABCDEFG00Z7657 FVT1
and so on Now file 2 looks like this:
>ABCDEFG0098GHT ATTATGCGCGCGCTCGCTGCTCG >ABCDEFG0098GHT ATTATGCGCGCGCTCGCTGCTCG >ABCDEFGQQ76890 TAGACAGATAGACAGATGACAGAT
Now I want to compare these two files. I specifically want to compare first column data of file 1 with that of the text present after the > sign in file 2 (data like ABCDEFG0098GHT). I only want to keep those data in file 2, that matches with POK or WOK in file 1. Can any body please help

20110113 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: file comparision and parsing
by Utilitarian (Vicar) on Jan 11, 2011 at 12:03 UTC
    Please add <code> tags around your data, you had to go through a preview page to post this and so you should have noticed it was badly formed.

    As to your problem:

    • open file one
    • while there are records in the file
      • if the line contains a string followed by one of your required strings
        • add the initial string to a hash of acceptable gene strings.
    • open file 2
    • while there are records in the file
      • if the line begins with a > and the rest of the line exists in your hash
        • write this line to a temp file
        • read the next line and add it to the temp file also (I think, not sure of what you have specified)
    • rename the temp file to file2 if you wish to overwrite the original version.
    Code that up and come back with any specific issues you are having.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: file comparision and parsing
by fisher (Priest) on Jan 11, 2011 at 09:56 UTC
Re: file comparision and parsing
by umasuresh (Hermit) on Jan 11, 2011 at 19:08 UTC
    As other monks have pointed out, use code tags.
    File comparisons and data extraction has been dealt with in multiple threads.
    Here is an example to help you get started Re: compare two files and update.
    Good Luck!