in reply to Re^8: Comparing 2 different-sized strings
in thread Comparing 2 different-sized strings
Could you just tell me what the "for" is when you call the subroutine in the main program? I have seen "for" only in the context of a for loop where you also supply the 3 parameters like initial index, final, and increment.
Sure.
If there are multiple matches in the haystack, the subroutine will return a list of start positions, one for each match.
By giving that list to for, it will execute the print substr statement for each position returned; with $_ taking on each of those start positions one after the other.
Hence, this
$hay = 'aacctgacctacgtttgacgatcgtacgtcagtcctccgtgctaactgacgtaaaaaaaata +cgtcccccccc'; $nee = 'acgtacgt'; print substr( $hay, $_-5, length( $nee ) + 10 ) for fuzzyMatch( \$hay, + \$nee, 3 );
prints the 10 matches (+the 5 bytes before and after):
acctgacctacgtttgac gacctacgtttgacgatc gtttgacgatcgtacgtc gacgatcgtacgtcagtc atcgtacgtcagtcctcc gtcagtcctccgtgctaa tgctaactgacgtaaaaa aactgacgtaaaaaaaat aaaaaaaatacgtccccc aaaatacgtcccccccc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Comparing 2 different-sized strings
by Anonymous Monk on Aug 18, 2013 at 13:20 UTC | |
by BrowserUk (Patriarch) on Aug 18, 2013 at 13:41 UTC | |
by AdrianJ217 (Novice) on Aug 18, 2013 at 16:19 UTC | |
by BrowserUk (Patriarch) on Aug 18, 2013 at 17:03 UTC | |
by AdrianJ217 (Novice) on Aug 18, 2013 at 17:11 UTC | |
| |
by AdrianJ217 (Novice) on Aug 18, 2013 at 13:26 UTC |