Hello Monkies,

I have a question - Can i use a second regex when looking through a line in a file.

For instance i am currently looking for Homo sapien in one line of a file, but i also want to look for chromosome 11 say. At the moment, i am saving the filtered data from Homo sapiens search into an array, then conducting the search on this to find the chromosome 11.

for (my $i = 0 ; $i<scalar @line; $i++) { if ($line[$i] =~ /^>/) { $current_subject = $line[$i]; chomp ($current_subject); push (@filtered_subjects, $current_subject); } } my @element;

So stored in the array is:

>gi|14670349|ref|NM_032999.1| Homo sapiens general transcription facto +r II, i (GTF2I), transcript >gi|2827179|gb|AF035737.1|AF035737 Homo sapiens general transcription +factor 2-I (GTF2I) mRNA, complete >gi|19908489|gb|AF343351.1| Mus musculus TFII-I repeat domain-containi +ng protein 3 beta 7 mRNA,

Then i look through each element looking for the species, which comes from a HTML list.
foreach my $z (@filtered_subjects) { chomp $z; @element = split('\|', $z); if($element[4] =~ /\Q$Homosapiens\E/) { push(@chromoLine, $z); } } }
Is this the best way to do it, or can i use something like:
if($element[4] =~ /\Q$Homosapiens$choromosome\E/)

Any help is appreciated.

thanks,
MonkPaul.


In reply to Double RegEx by MonkPaul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.