Well, you ARE outputting the "Hydrophobic stretch found" line each time there is a match:

while($seq =~ /([VILMFWCA]{8,})/g){ #search for desired sequence my $location = pos($seq); #find location my $length = length($1); #determine length print "Hydrophobic stretch found in: ", $header, "\n"; #printing o +utputs for results print $1, "\n"; print "The match was at position: ", $location - $length + 1, "\n\ +n"; }

If you only want to print it once, the easiest way is to introduce a flag indicating whether it's already been output. Declare a new variable in front of your while loop there, and then check and set it inside the loop body:

my $header_printed = 0; # header for this thingamabob was not yet prin +ted while($seq =~ /([VILMFWCA]{8,})/g){ #search for desired sequence my $location = pos($seq); #find location my $length = length($1); #determine length unless($header_printed) { print "Hydrophobic stretch found in: ", $header, "\n"; #printi +ng outputs for results $header_printed = 1; } print $1, "\n"; print "The match was at position: ", $location - $length + 1, "\n\ +n"; }

Obviously this could be written more concisely, but this way it's clear what's going on.

Does this help you?


In reply to Re: One header for multiple results by AppleFritter
in thread One header for multiple results by lairel

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.