in reply to BASIC MATH WITH DATA
I hope that gets you started!#!perl -w use strict; my @lines; while (<>) { push @lines, $_; shift @lines if @lines > 10; } chomp(@lines); my @cols; my $total = 0; for (@lines) { @cols = split /:/; $total += $cols[3]; } my $average = $total / (@lines || 1); # if no lines, avoid division by zero print "Average of column 3 for the last ", scalar(@lines), " days: $average\n";
Update: Have to specify $_ in the call to push. Bad chipmunk! No acorns!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: BASIC MATH WITH DATA
by joachim (Initiate) on Jan 26, 2001 at 01:42 UTC | |
by chipmunk (Parson) on Jan 26, 2001 at 01:55 UTC | |
by joachim (Initiate) on Jan 26, 2001 at 04:40 UTC | |
by tye (Sage) on Jan 26, 2001 at 07:09 UTC | |
by joachim (Initiate) on Jan 26, 2001 at 08:34 UTC | |
| |
by lemming (Priest) on Jan 26, 2001 at 01:59 UTC | |
by joachim (Initiate) on Jan 26, 2001 at 03:39 UTC | |
by lemming (Priest) on Jan 26, 2001 at 03:44 UTC | |
by chipmunk (Parson) on Jan 26, 2001 at 03:45 UTC |