in reply to Pattern Searching
I must be missing something obvious, but I can reproduce the basics of your output by a few nested loops and a regex.
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 Deltronics
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Pattern Searching
by Anonymous Monk on Nov 12, 2012 at 15:34 UTC | |
by choroba (Cardinal) on Nov 12, 2012 at 15:35 UTC |
In Section
Seekers of Perl Wisdom