We don't bite newbies here... much | |
PerlMonks |
Why am I getting wrong result in counting the number and kind of 2-letter in 3-letter words in a string?by supriyoch_2008 (Monk) |
on May 01, 2012 at 13:19 UTC ( [id://968241]=perlquestion: print w/replies, xml ) | Need Help?? |
supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question: Hi Perlmonks, I have a small string my $seq="ATCATCATCATC"; consisting of four 3-letter word i.e. ATC. For all the 3-letter words I am interested in counting the number and the kind of 2-letter at 1st & 2nd positions (AT) of all 3-letter words, similarly for 2nd & 3rd positions (TC) and for 1st & 3rd positions (AC). I have written the following code which gives correct result for 1st & 2nd positions (AT=4) and for 2nd & 3rd positions (TC=4). But I am getting wrong result in counting the number and kind of Letters at 1st & 3rd positions (i.e. AC=0; it should be AC=4). The code that I have used goes as follows:
I have got the following wrong result for "Letters at 1st & 3rd Positions" in last line of result for AC i.e. AC=0; it should be AC=4
I shall be glad if any perlmonk can help me correct the mistake (possibly at Line 15) and further modify the code so that each result comes out after being assigned to a separate scalar variable (like $AT12 for AT at 1st & 2nd positions, similarly $TC12, $AC12 . . . $TC13,$AC13. In the given code, all results come out in a lot.
Back to
Seekers of Perl Wisdom
|
|