Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Seek and Find

by hbrown.bios (Initiate)
on Feb 08, 2016 at 17:06 UTC ( [id://1154648]=perlquestion: print w/replies, xml ) Need Help??

hbrown.bios has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys, I'm still pretty new to perl, so I'm not even sure is this will work, but here is what I am trying to do. I have 2 files. say file A has a list of numbers (which I can put into an array because there aren't very many of them) and I want to search file B which has 7 columns. I want perl to print the matching line to a new file if column 2 matches a value in file a (or the array) AND matches a search phrase in column 7 and if the value in column 4 falls into a specified range. Any and all help would be greatly appreciated!

Replies are listed 'Best First'.
Re: Seek and Find
by Laurent_R (Canon) on Feb 08, 2016 at 17:49 UTC
    Load the values of your first file into a hash rather than an array, lookup will be easier and performance much faster.

    Then read the second file and check if the values can be found in the hash.

    Provide some sample data if you need more help.

      So here is an example of some of may data: GLU 66 PRO 436 9.116044197 Blank Asterisk GLU 67 ASN 427 9.34269896 Asterisk Asterisk What I would like it to do is if column 2 matches a number in the hash (or array), and the value in column 4 is within a given range of numbers, and column 7 matches a search phrase such as "Asterisk" it would print the entire matching line to a new file, and then for it to continue searching until the end of the document.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found