in reply to Need Help with Maybe a Regex Issue
Under the assumption that the strings you are looking for are always the values of the /locus_tag, it is better to load the values you are searching for into a hash to use the exists function in addition to a regex. So you could loop over your second file, extract the value of the /locus_tag and if it exists in the hash, print the next line.
use strict; use warnings; my %hashOfVals; open(my $tmp, "<", "NC_001903.gbk.txt") || die "Could not open $!"; undef @hashOfVals{map {chomp; $_} <$tmp>}; close($tmp); open(my $tmpFile, "<", "cp26_diffexpr.txt") || die "Could not open $!" +; my @arrayFromCSV = <$tmpFile>; chomp @arrayFromCSV; close($tmpFile); for (0..$#arrayFromCSV-1) { print "$1: $arrayFromCSV[$_+1]\n" if $arrayFromCSV[$_] =~ /locus_tag="(.*)"/ and exists $hashOfV +als{$1}; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Need Help with Maybe a Regex Issue
by sharkbait (Initiate) on Feb 27, 2014 at 15:43 UTC |
In Section
Seekers of Perl Wisdom