There are two things that make it hard to provide a good answer for you. First, you seem to be writing C in Perl. That we can cope with and we can help you take advantage of Perl to clean up your code, but the bad side effect is that declaring all your variables up front makes it very hard to know what their true scope is.

The second and more significant problem is that we don't actually know what you are trying to do. You don't give us any sample data. In fact you seem to be going out of your way to obscure what your data actually looks like. I'm fairly sure your real data isn't "characters", but is in fact "numbers" because your manipulations just don't make sense otherwise. It would help us a lot to help you if you gave some sensible sample data and some sensible looking expected output.

You might like to use the following Perlish script based on what your sample code seems to be doing and, if it doesn't solve your problems, revise it to demonstrate where your problems are.

use strict; use warnings; my $runs = 3; my $range = 3; my @X_info = ("1\t2\t3\t4", "1\t3\t6\t8", "1\t4\t9\t16", "1\t5\t12\t32"); # Outer loop: Repeat "$runs" times for my $run (1 .. $runs) { my @tmp; my $pi_sum; my $L_sum; my $differences_sum; my $coverage_sum; push @tmp, $X_info[rand @X_info] for 1 .. $range; my @PAR1 = splice @tmp, 0, 3,; for my $k (0 .. @PAR1 - 1) { my @PAR1_info = $PAR1[$k]; my @values = split '\t', $PAR1_info[0]; $pi_sum += $values[0]; $L_sum += $values[1]; $differences_sum += $values[2]; $coverage_sum += $values[3]; } my $PAR1_diversity = (($pi_sum / $L_sum) / ($differences_sum / $coverage_sum)); printf "%2d: %6.3f\n", $run, $PAR1_diversity; }

Prints:

1: 0.519 2: 0.630 3: 0.519
True laziness is hard work

In reply to Re: Assigning Variables to String Elements by GrandFather
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.