Output:use Modern::Perl; my @patterns = qw/GAATTC CCWGG/; while ( my $sequence = <DATA> ) { my @matches; while ( $sequence =~ m/($patterns[0]|$patterns[1])/g ) { for my $expr ( 1 .. $#- ) { push @matches, $-[$expr] .. $+[$expr] - 1; } } say "@matches"; } __DATA__ GAATTCACGGATAGCCWGGTACGATGATAGATGAATTCGACTAGAATGCCWGGAAGAATgGAATTC GAATTCACGGATAGCCWGGTACGATGATAGATGAATTCGACTAGAATGCCWGGAAGAATgGAATTC GAATTCACGGATAGCCWGGTACGATGATAGATGAATTCGACTAGAATGCCWGGAAGAATgGAATTC
0 1 2 3 4 5 14 15 16 17 18 32 33 34 35 36 37 48 49 50 51 52 60 61 62 6 +3 64 65 0 1 2 3 4 5 14 15 16 17 18 32 33 34 35 36 37 48 49 50 51 52 60 61 62 6 +3 64 65 0 1 2 3 4 5 14 15 16 17 18 32 33 34 35 36 37 48 49 50 51 52 60 61 62 6 +3 64 65
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re: Pattern Searching
by CountZero
in thread Pattern Searching
by aseee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |