in reply to How to compute the avg of a column of numbers
Cheers - L~R#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'file.txt'; open (INPUT, '<', $file) or die "Unable to open file for reading : $!" +; my @values; while ( <INPUT> ) { chomp; my @col = split /\t/; # Assume basic tab delimited push @values, $col[3]; # Column 4 is what we want } my $total = 0; $total += $_ for @values; my $average = $total / @values;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to compute the avg of a column of numbers
by pbeckingham (Parson) on Mar 31, 2004 at 20:23 UTC | |
by Limbic~Region (Chancellor) on Mar 31, 2004 at 21:36 UTC |