in reply to Re: Code optimization help and troubleshooting
in thread Code optimization help and troubleshooting
Could I get some help in the debugging, somehow, in the sequence after 1-10 character the 11th character is getting truncated.
The relevant part of the code has the following structure:
for (my $pos = 1; $pos <= length($sequence); $pos++) { ... foreach my $k (...) { ... if ($pos == $p1) { ... for (my $p = ...) { ... $pos++; } } } ... }
Incrementing the same variable (viz. $pos) in two places like this is asking for trouble. And, sure enough, within the inner for loop there are one too many increments, producing a typical off-by-one error. You can fix this by decrementing $pos immediately after the inner loop has completed:
if ($pos == $p1) { $FLAG = 1; push @temp, $red; for my $p ($p1 .. $p2) { my $s = substr($sequence, $p - 1, 1); push @temp, $s; push @temp, $brk if $p == int($p / 50) * 50; $pos++; } $pos--; # <-- ADD THIS push @temp, $span; }
Note that it is not necessary to set $FLAG each time through the loop.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|