supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get the correct count
by GrandFather (Saint) on Apr 19, 2012 at 11:13 UTC | |
by eyepopslikeamosquito (Archbishop) on Apr 19, 2012 at 11:48 UTC | |
|
Re: How to get the correct count
by Ratazong (Monsignor) on Apr 19, 2012 at 10:59 UTC |