in reply to Double check for positions
since the next match blends into the first one
Actually it doesn't.
use strict; use warnings; use Test::More tests => 2; my $pos = match_positions ('GCTTCTTGC', 'AGCTTCTTGCGCTTCTT'); is ($pos, '2 9 ', 'Matched'); # This fails because you have only one o +ccurrence. $pos = match_positions ('GCG', 'AGCGCGT'); is ($pos, '2 4 ', 'Matched'); sub match_positions { my ($regexp, $sequence) = @_; my @positions = ( ); while ( $sequence =~ m/$regexp/ig ) { my $newpos = pos($sequence) - length($&) + 1; push @positions, $newpos; pos($sequence) = $newpos; } return "@positions "; }
Update: fixed the test count to include the second easier-to-follow example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Double check for positions
by bisimen (Acolyte) on Oct 18, 2017 at 13:22 UTC | |
by hippo (Archbishop) on Oct 18, 2017 at 13:27 UTC | |
by bisimen (Acolyte) on Oct 18, 2017 at 13:35 UTC | |
by soonix (Chancellor) on Oct 18, 2017 at 13:38 UTC |