Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are the points you need to change<br> Use another variable for the headers<br></p> <pre><code>my $count = 0; my @header = (); my @average = (); </code></pre> <p>then change the logic inside if statement<br></p> <pre><code>if ( $count == 1 ) { @header = @columns; } </code></pre> <p>Now don't use the <code>@average</code> for the limit, use <code>$i &lt; scalar @columns</code> for else statement. Initially <code>@average</code> is zero, you will never get inside the for loop ever.</p> <pre><code>else { for( my $i = 1; $i &lt; scalar @columns; $i++ ) { $average[$i] += $columns[$i]; } } </code></pre> <p>Finally add <code>-1</code> to your counter. Remember you increment your counter when you parse your header</p> <pre><code>for( my $i = 1; $i &lt; scalar @average; $i++ ) { print $average[$i]/($count-1), "\n"; } </code></pre> <p>Here is the final code<br> You can take advantage of <code>@header</code> to display the result neatly</p> <pre><code>#!/usr/bin/perl -w use strict; my $infile = "Lab1_table.txt"; # This is the file path open INFILE, $infile or die "Can't open $infile: $!"; my $count = 0; my @header = (); my @average = (); while (&lt;INFILE&gt;) { chomp; my @columns = split /\t/; $count++; if ( $count == 1 ) { @header = @columns; } else { for( my $i = 1; $i &lt; scalar @columns; $i++ ) { $average[$i] += $columns[$i]; } } } for( my $i = 1; $i &lt; scalar @average; $i++ ) { print $average[$i]/($count-1), "\n"; } </code></pre> <p>There are other ways to write this code but I thought it would be better to just correct your code so that you can easily understand what is wrong with your code. Hope it helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload