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);
-
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.