Note that there are some explanatory texts on larger screens.

plurals
  1. POFind multiple substrings in strings and record location
    text
    copied!<p>The following is the script for finding consecutive substrings in strings. </p> <pre><code>use strict; use warnings; my $file="Sample.txt"; open(DAT, $file) || die("Could not open file!"); #worry about these later #my $regexp1 = "motif1"; #my $regexp2 = "motif2"; #my $regexp3 = "motif3"; #my $regexp4 = "motif4"; my $sequence; while (my $line = &lt;DAT&gt;) { if ($line=~ /(HDWFLSFKD)/g){ { print "its found index location: ", pos($line), "-", pos($line)+length($1), "\n"; } if ($line=~ /(HD)/g){ print "motif found and its locations is: \n"; pos($line), "-", pos($line)+length($1), "\n\n"; } if ($line=~ /(K)/g){ print "motif found and its location is: \n"; pos($line), "-",pos($line)+length($1), "\n\n"; } if ($line=~ /(DD)/g){ print "motif found and its location is: \n"; pos($line), "-", pos($line)+length($1), "\n\n"; } }else { $sequence .= $line; print "came in else\n"; } } </code></pre> <p>It matches substring1 with string and prints out position where substring1 matched. The problem lies in finding the rest of the substrings. For substrings2 it starts again from the beginning of the string (instead of starting from the position where substring1 was found). The problem is that every time it calculates position it starts from the beginning of string instead of starting from the position of the previously found substring. Since substrings are consecutive substring1, substring2, substring3, substring4, their positions have to occur after the previous respectively.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload