length probably isn't doing what you think it does. Try: for($k = 0; $k < @PAR1; $k++).

Or, even better:

for my @PAR1_info (@PAR1) { $pi = split('\t', $PAR1_info[0]); $pi_sum = $pi_sum + $pi; $L = split('\t', $PAR1_info[1]); $L_sum = $L_sum + $L; $differences = split('\t', $PAR1_info[2]); $differences_sum = $differences_sum + $differences; $coverage = split('\t', $PAR1_info[3]); $coverage_sum = $coverage_sum + $coverage; my $PAR1_diversity = (($pi_sum/$L_sum)/($differences_sum/$cove +rage_sum)); }

Edit: As AnomalousMonk pointed out, the above code doesn't compile. That's what I get for neither thinking nor testing. What I thought I was thinking was more like the following, which does compile (after a bit of testing, fixing bugs and making presumptive changes):

$pi_sum = 0; $L_sum = 0; $differences_sum = 0; $coverage_sum = 0; for my $PAR1 (@PAR1) { my @PAR1_info = split(/\t/, $PAR1); $pi = $PAR1_info[0]; $pi_sum = $pi_sum + $pi; $L = $PAR1_info[1]; $L_sum = $L_sum + $L; $differences = $PAR1_info[2]; $differences_sum = $differences_sum + $differences; $coverage = $PAR1_info[3]; $coverage_sum = $coverage_sum + $coverage; my $PAR1_diversity = (($pi_sum/$L_sum)/($differences_sum/$c +overage_sum)); }

Which could be reduced to:

$pi_sum = 0; $L_sum = 0; $differences_sum = 0; $coverage_sum = 0; for my $PAR1 (@PAR1) { my ($pi, $L, $differences, $coverage) = split(/\t/, $PAR1); $pi_sum = $pi_sum + $pi; $L_sum = $L_sum + $L; $differences_sum = $differences_sum + $differences; $coverage_sum = $coverage_sum + $coverage; my $PAR1_diversity = (($pi_sum/$L_sum)/($differences_sum/$c +overage_sum)); }

And, prior to this, chomping the input is probably appropriate:

my @X_info = <CHR_X_INPUT>; chomp(@X_info);

In reply to Re: Assigning Variables to String Elements by ig
in thread Assigning Variables to String Elements by ccelt09

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.