Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-16 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found