Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

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

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



  • 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 surveying the Monastery: (4)
As of 2024-04-25 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found