Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Specifying comments for each line to give you clear understanding</p> <pre><code>#!/usr/bin/perl -w use strict; use warnings; my $infile = "Lab1_table.txt"; # input file path open INFILE, $infile or die "Can't open $infile: $!"; # input file opened my $outfile = "Lab1_tableoutput.txt"; # output file path open OUTFILE, "&gt;$outfile" or die "Cannot open $outfile: $!"; # output file opened my $count = 0; # count variable to check for header row in file my @header = (); # variable to store headers/column names of file my @average = (); # variable to store average calculated for each column while (&lt;INFILE&gt;) { chomp; my @columns = split /\s+/; # \s stands for [\ \t\r\n\f] $count++; if ( $count == 1 ) { @header = @columns; # executed only once for header } else { # else column executed for remaining rows for( my $i = 1; $i &lt; scalar @columns; $i++ ) { # $i=1 means skip first column $average[$i] += $columns[$i]; # calcuate average for each row } } } for( my $i = 1; $i &lt; scalar @average; $i++ ) { print OUTFILE $average[$i]/($count-1), "\n"; # This will write to output file } close OUTFILE; </code></pre> <p>Use <code>print OUTFILE $average[$i]/($count-1), "\n";</code> to write to file.</p> <p>Error <code>Argument "" isn't numeric in addition (+) at line 25, &lt;INFILE&gt; line X</code> could be if values in columns which you are adding,by any chance has string in it and not number.Check your input file.</p> <p>Note: I am not getting above error.Script runs smooth with above data.However if I change one of number to string,I get this error. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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