No such thing as a small change | |
PerlMonks |
Re: extract values from file if greater than valueby Cristoforo (Curate) |
on Jun 15, 2016 at 18:18 UTC ( [id://1165767]=note: print w/replies, xml ) | Need Help?? |
Not knowing if the fields may repeat in either file as anonymous monk asked, I can only guess a solution. The best way to solve this would probably use a lookup hash (as in my solution below), provided the first 2 fields in file 1 don't repeat.
This only prints the values - not sure how you want to store in an array (as you mentioned). Update: Added the 'defined' operator to the if statement so a 'min' value of '0' will be accepted. Without testing for defined, a '0' value would cause the if statement to be wrongly false. Also, like Marshall's solution, the temporary files I created were just for this example. You would need to open your files in the normal way open my $fh1, '<', 'yourfilename' or die $!. Update 2: Noting Marshall's comment on separating $data{"$chr$bp"} by a space to be safer, $data{"$chr $bp"}, I used the seldom used idiom $data{$chr,$bp} where a comma separated series of terms as the key to a hash are joined together by the '$SUBSCRIPT_SEPARATOR', $;. Also, I'm wondering what the purpose of next if /CHR/; is in his code. It is hard to see whithout a better data sample for the file he is reading.
In Section
Seekers of Perl Wisdom
|
|