Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Assigning Variables to String Elements

by GrandFather (Saint)
on Dec 07, 2013 at 10:31 UTC ( [id://1066115]=note: print w/replies, xml ) Need Help??


in reply to Assigning Variables to String Elements

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1066115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-03-28 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found