I'm not to clear on what you're trying to do, but here are some things to consider... Since the third column, corresponding to the $letter1 variable seems to remain a single character, and you don't seem to be doing anything more with it than counting it, try this technique instead. I'm unclear as to how you want to scan your @prettybase array, but you might want to consider making the processing of an input record into a subroutine like this:
## ## Will process the records between $start and $end ## and count the occurances of the third ## field, returning the total count and a ## has containing the individual counts keyed ## by the letter. ## sub processRec { my($arrayRef, $start, $end) = @_ ; my($i, $total, $letter_counts) ; my($position, $patient, $letter1, $letter2) ; for( $i = $start ; $i <= $end ; $i++ ) { ($position, $patient, $letter1, $letter2)=split(/\t/, $arrayRef->[ +$i]); $letter_counts->{uc $letter1} += 1 ; } $total = 0 ; for( values %$letter_counts ) { $total += $_ ; } # for return($total, $letter_counts) ; } @prettybase = map chomp, <INPUT> ; # # do something to determine start and stop points # ($total, $counts) = processRec(\@prettybase, start, end) ; while( ($letter, $count) = each %$counts ) { print "$letter => ", ($count*100)/$total, "\n" ; }
You may want to consider 'pre-splitting' the @prettybase array into an array of array refs just so you don't have to keep resplitting the lines. This would be good if your input files are huge, and you're going back and forth over it many times.

In reply to Re: Finding elements without a counter... by ptkdb
in thread Finding elements without a counter... by bioinformatics

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.