Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

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

length probably isn't doing what you think it does. Try: for($k = 0; $k < @PAR1; $k++).

Or, even better:

for my @PAR1_info (@PAR1) { $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_sum/$cove +rage_sum)); }

Edit: As AnomalousMonk pointed out, the above code doesn't compile. That's what I get for neither thinking nor testing. What I thought I was thinking was more like the following, which does compile (after a bit of testing, fixing bugs and making presumptive changes):

$pi_sum = 0; $L_sum = 0; $differences_sum = 0; $coverage_sum = 0; for my $PAR1 (@PAR1) { my @PAR1_info = split(/\t/, $PAR1); $pi = $PAR1_info[0]; $pi_sum = $pi_sum + $pi; $L = $PAR1_info[1]; $L_sum = $L_sum + $L; $differences = $PAR1_info[2]; $differences_sum = $differences_sum + $differences; $coverage = $PAR1_info[3]; $coverage_sum = $coverage_sum + $coverage; my $PAR1_diversity = (($pi_sum/$L_sum)/($differences_sum/$c +overage_sum)); }

Which could be reduced to:

$pi_sum = 0; $L_sum = 0; $differences_sum = 0; $coverage_sum = 0; for my $PAR1 (@PAR1) { my ($pi, $L, $differences, $coverage) = split(/\t/, $PAR1); $pi_sum = $pi_sum + $pi; $L_sum = $L_sum + $L; $differences_sum = $differences_sum + $differences; $coverage_sum = $coverage_sum + $coverage; my $PAR1_diversity = (($pi_sum/$L_sum)/($differences_sum/$c +overage_sum)); }

And, prior to this, chomping the input is probably appropriate:

my @X_info = <CHR_X_INPUT>; chomp(@X_info);

In reply to Re: Assigning Variables to String Elements by ig
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 taking refuge in the Monastery: (3)
As of 2024-04-24 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found