in reply to Re: substr help
in thread substr help
Surely that should be
for ( my $loc = 0; $loc <= length($dna) - 10; $loc += $increment ) {
Otherwise his last few strings won't be 10 characters long. Even though I have done this exact thing (sliding window with overlaps) in the past using a C-style for loop, I think I'd probably write it like this these days:
or more likelymy $end = int((length($dna) - 10)/3); for my $i (0..$end) { push @windows, substr($dna,$i*3,10); }
my @windows = map { substr($dna,$_*3,10) } 0..int((length($dna)-10)/3) +;
|
|---|