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;

In reply to 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
in thread 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 supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.