To answer your primary question, the /^$species_filter/ match is failing because the $species_filter does not come at the beginning of the string. Remove the caret to match correctly.

for the string:

'AF035737 Homo sapiens general transcription factor 2-I (GTF2I) mRNA, +complete.' /Homo sapiens/ will match /^Homo sapiens/ will not

However there are many other things wrong with this routine. Here's a few comments.


sub filter_by_Species() # Don't use prototypes unless you NEED them. And even then, you probab +ly don't. open( NEWALIGN, "<blast_files/$newBlastFile") || die "$!"; #use lexical filehandles and three argument opens to prevent # obscure bugs. The || is very high precedent. Not wrong # really, but unecessarily powerful. #read results file one line at a time my @resultLine = <NEWALIGN>; # Arggh. Read entire file into an array at once. my @subjects = []; # reference to empty array # nope. Array whose first element is a reference to an empty array #so I produce a hash with key = >gi line of report and value = all lin +es after until next >gi # I saw no "greater than" in the example data... for (my $i = 0 ; $i<scalar @resultLine; $i++) # C style loops. Avoid unless necessary. They work ok but # clutter up the script and make it harder figure out what # you are doing. if ($resultLine[$i] =~ /^>/) # again, no "greater than" in the example data... { $current_subject = $resultLine[ $i ]; chomp ($current_subject); push (@subjects, $current_subject); $alignment->{$current_subject} = ""; $alignment->{$current_subject}.$resultLine[ $i ]; } # you never use the %$alignment hash anywhere so why bother? my @elements; my $boolean; # declare variables in the smallest scope possible foreach my $z (@subjects) { chomp $z; # already chomped in previous loop show_Output($boolean, $z, @elements); # boolean ALWAYS equal 0. Why not just pass 0?

If I were to write this getting the same functionality it would look something like:


sub filter_by_Species { print 'New Blast File Opened<BR>'; open(my $newalign, '<', "blast_files/$newBlastFile") or die $!; print 'Filtering Data........Please wait<P>'; my @subjects; while <$newalign> { push @subjects, $_ if (/^>gi/) } print '<TABLE BORDER=2>'; print '<th align=center><B>Status</B></th>'; print '<th align=center><B>Information on new hits</B></th>'; for (@subjects) { chomp; my @elements = split '\|'; if($elements[-1] =~ /$species_filter/) { print "<TR><TD>Match to $species_filter"; show_Output(0, $_, @elements); } } print'</TABLE><BR><BR>'; }

Also, since your show_Output used blank prototypes, it never recieves the passed values. Again, don't use prototypes unless you NEED to. Never mind that last bit, that is not true.

Update: fixed a few typos.


In reply to Re: RegExpression fails to work by thundergnat
in thread RegExpression fails to work 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.