ccelt09 has asked for the wisdom of the Perl Monks concerning the following question:
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)); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assigning Variables to String Elements
by jethro (Monsignor) on Dec 07, 2013 at 02:35 UTC | |
|
Re: Assigning Variables to String Elements
by GrandFather (Saint) on Dec 07, 2013 at 10:31 UTC | |
|
Re: Assigning Variables to String Elements
by Kenosis (Priest) on Dec 07, 2013 at 07:52 UTC | |
|
Re: Assigning Variables to String Elements
by ig (Vicar) on Dec 07, 2013 at 00:47 UTC | |
by AnomalousMonk (Archbishop) on Dec 07, 2013 at 15:13 UTC | |
by ccelt09 (Sexton) on Dec 07, 2013 at 01:41 UTC | |
by ig (Vicar) on Dec 07, 2013 at 06:03 UTC | |
by dave_the_m (Monsignor) on Dec 07, 2013 at 11:07 UTC | |
|
Re: Assigning Variables to String Elements
by toolic (Bishop) on Dec 07, 2013 at 00:15 UTC | |
by ccelt09 (Sexton) on Dec 07, 2013 at 00:26 UTC |