in reply to One header for multiple results

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?

Replies are listed 'Best First'.
Re^2: One header for multiple results
by lairel (Novice) on Oct 21, 2015 at 15:09 UTC
    Thank you! It did exactly what I wanted.