I was wondering if anyone knows how to simplify, or generalize this code. It gives the correct answer, however it is only applicable to the current situation. My code is as follows:
sub longestRepeat{
# list of argument @_ is: (sequence, nucleotide)
my $someSequence = shift(@_); # shift off the first argument from the list
my $whatBP = shift(@_); # shift off the second argument from the list
my $match = 0;
if ($whatBP eq "AT"){
if ($someSequence =~ m/(([A][T])\2\2\2\2\2)/g) {
$match = $1
}
return $match;
}
if ($whatBP eq "TAGA"){
if ($someSequence =~ m/(([T][A][G][A])\2\2)/g) {
$match = $1
}
return $match;
}
if ($whatBP eq "C"){
if ($someSequence =~ m/(([C])\2\2)/g) {
$match = $1
}
return $match;
}
}
My question is, in the second if statement, I have it set to a set amount of that pattern being repeated (applicable for the string we were given). However, is there a way to keep doing a while loop to search through the \2 (pattern repeat)? What I mean is can this: if ($someSequence =~ m/(([A][T])\2\2\2\2\2)/g) be simplified and generalized with a while loop