http://www.perlmonks.org?node_id=967308

supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Ref: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?
  • Select or Download Code

Replies are listed 'Best First'.
Re: Ref: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?
by johngg (Canon) on Apr 26, 2012 at 11:35 UTC

    The first thing that jumps out of the code is that you are initialising and incrementing elements of %first, %second and %third but only printing results from %first.

    Cheers,

    JohnGG

Re: Ref: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?
by ww (Archbishop) on Apr 26, 2012 at 11:39 UTC

    You've been offered the tools to learn how to do this yourself; you've been given solutions to most of the many questions you've asked en route to this one. Please consider either using these gifts to good effect... or hire a programmer.

Re: Ref: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?
by brx (Pilgrim) on Apr 26, 2012 at 12:21 UTC

    It's difficult to explain in english that... I don't undertand what is really your problem. The code in Re: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string? is not very nice but it is simple and I don't understand the aim of your corrections.

    You said: I didn't write "use strict" at the beginning of the code intentionally. -- Don't do that! It's baaaad! use strict; is your best friend!

    It seems you don't what to use an hash. Why ? $A1,$G1...$C3: 12 variables!!!

    Finnaly, my script was probably not so simple and I propose another one, with one hash and keys like "A1" or "G3".

    #!perl use strict; use warnings; my $seq = "ATCGGCGCCTAT" ; my %poscount; my @trilet = $seq =~ /.../g; #print join "\n",@trilet; foreach my $let ('A','T','G','C') { #init $poscount{$let.'1'}=0; $poscount{$let.'2'}=0; $poscount{$let.'3'}=0; } foreach my $tri (@trilet) { print "processing '$tri'\n"; my $let1 = substr $tri,0,1; $poscount{$let1.'1'}++; print $let1,"1++\t"; my $let2 = substr $tri,1,1; $poscount{$let2.'2'}++; print $let2,"2++\t"; my $let3 = substr $tri,2,1; $poscount{$let3.'3'}++; print $let3,"3++\n\n"; } foreach my $pos (1,2,3) { foreach my $let ('A','T','G','C') { my $letpos = $let.$pos; print "$letpos=$poscount{$letpos}; " } print "\n"; } __END__ processing 'ATC' A1++ T2++ C3++ processing 'GGC' G1++ G2++ C3++ processing 'GCC' G1++ C2++ C3++ processing 'TAT' T1++ A2++ T3++ A1=1; T1=1; G1=2; C1=0; A2=1; T2=1; G2=1; C2=1; A3=0; T3=1; G3=0; C3=3;