Edits have been made to A Question with Nesting Arrays and I can explain more clearly now. I did indeed mean to restructure my input data by sampling with replacement, not shuffling. Each element of the input array is a string of characters, comprised itself of 4 tab delimited elements (shown below)

A1 B1 C1 D1 A2 B2 C2 D2 A3 B3 C3 D3

After restructuring my data I further subdivide the new array  @tmp with the splice function. With the last for loop and looping variable k I wish to assign each of the four elements in a string to 4 separate variables. The difficulties I am encountering: the code below assigns the length of the string, 4, to each of my variables and the for loop does not loop. For example I wish the variable pi to equal A1 but it is assigned the value 4. I don't understand why the split function isn't working or why the last for loop doesn't loop/increase k.

my $runs = 1; # for testing code #my $runs = 1000; # 1_000 - the num of times we repeat #my $runs = 100000; # 10 _000 - the num of times we repeat #my $runs = 1000000; # 100_000 - the num of times we repeat # Program vars my $i; # a looping variable my $j; # another looping variable my $k; # another looping var my $range = 1552; # total number of array elements my @tmp; # empty array to push data into #Looping Variables my $pi; my $pi_sum; my $L; my $L_sum; my $differences; my $differences_sum; my $coverage; my $coverage_sum; ; ; my $chr_X_input = "bootstrap_data.txt"; open (CHR_X_INPUT, "<$chr_X_input") or die "can't open chromosome X in +put"; my @X_info = <CHR_X_INPUT>; # Outer loop: Repeat "$runs" times for ($j = 0; $j < $runs; $j++) { for ($i = 0; $i < $range ; $i++) { # choose a randomly selected string of 4 elements from our arr +ay push (@tmp, $X_info[int(rand($range))]); } my @PAR1 = splice(@tmp, 0, 26,); for ($k = 0; $k < length(@PAR1) + 1 ; $k++) { my @PAR1_info = $PAR1[$k]; $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_su +m/$coverage_sum)); } }

In reply to 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.