in reply to Regex KungFu help needed
#!/usr/bin/perl use strict; use warnings; my @real_count = (0,0,0,0); my $sequence = "GGGGGGGAGAAAAAAAAAAAAAAAGAAGGA"; my @pattern; $pattern[0] = "A(?=AAAA)"; $pattern[1] = "G(?=GGGG)"; $pattern[2] = "G(?=GAGA)"; $pattern[3] = "G(?=AAGG)"; foreach my $i (0..$#pattern) { $real_count[$i]++ while ($sequence =~ /$pattern[$i]/g); } foreach (@real_count) { print "$_\n"; }
Note I also swapped your error prone for loop for a foreach loop with the range operator.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex KungFu help needed
by johngg (Canon) on Oct 02, 2009 at 15:12 UTC | |
by AnomalousMonk (Archbishop) on Oct 02, 2009 at 22:59 UTC | |
by johngg (Canon) on Oct 03, 2009 at 11:03 UTC | |
by grizzley (Chaplain) on Oct 05, 2009 at 07:17 UTC | |
|
Re^2: Regex KungFu help needed
by Anonymous Monk on Oct 02, 2009 at 18:25 UTC |