in reply to Re: BASIC MATH WITH DATA
in thread BASIC MATH WITH DATA
So the message in the Data.log file would read "<Filename> Average is <average> the last was <most resent entry for col3>" Thank you.. this has been good experience..... wish something like this was in the book I bought. joachim#!/usr/bin/perl -w $infile = shift; $outfile = shift; open(IN, $infile) || die("Can't open input file $infile - $!"); open(OUT, ">$outfile") || die("Can't open output file $outfile +- $!"); use strict; my $text; 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 ***** error here***** $text= "Average of column 3 for the last " + ;#, scalar(@lines)," days: $average\n"; print OUT "$text\n"; close IN; close OUT ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: BASIC MATH WITH DATA
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 tye (Sage) on Jan 26, 2001 at 09:39 UTC | |
|
Re^3: Basic math with Data
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 |