in reply to Searching for a word that may only exist in part
here is one way, though index() would surely be faster than m// here.
updated: to provide better(?) var namesmy $sequence = "GAATGTTTTAGCAATCTCTTTCTGTCATGAATCCATGGCAGTGACCATACTAAT +GGTGACTGCCATTGATGGAGGGAGACACA"; my $find = "CTGGATAAGAATGTTTTAGCAATCTCTT"; my $found; MATCH: { my $tail = $find; while ( length($tail) > 2 and not $found ) { ($found) = $sequence =~ /($tail)/ # find match or substr( $tail, 0, 1, ''); # or eat first letter } last MATCH if $found; my $head = $find; ## can chop first since exact match already failed while ( chop $head and length($head) > 2 and not $found ) { ($found) = $sequence =~ /($head)/; } } print "found? $found\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Searching for a word that may only exist in part
by GrandFather (Saint) on Oct 19, 2006 at 01:41 UTC | |
by mreece (Friar) on Oct 19, 2006 at 02:40 UTC |