Dear PerlMonks,
I am a beginner in perl programming. I am getting wrong result in counting a regular expression from my program. I have given the program below. Can you help me to sort out this problem?
#!usr/bin/perl-w @k = ‘CCATGNNNTAACCNNATGNNTAGCC’; $k = join( '', @k); # Remove whitespace $k=~ s/\s//g; # Count number of bases & regular expressions $b=length($k); print "\n Number of bases (including N): $b.\n"; # Count number of A and regular expression (i.e. gene) $A=0; $GENE=0; while($k=~ /A/ig){$A++} while($k=~ /[AG]TG.*T[AG][AG]/ig){$GENE++} print "\n A= $A; GENE(S)= $GENE; \n\n"; exit;
I have got the following wrong result:
Number of bases (including N): 25.
A= 5; GENE(S)= 1;
But correct result should be:
Number of bases (including N): 25.
A= 5; GENE(S)= 2;
Actually the value of GENE(S) should be 2 as there are two such regular expressions (sequences) in the array @DNA. Please suggest me the corrections in the code.
In reply to How to get the correct count by supriyoch_2008
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |