in reply to Re: Re: Re: BASIC MATH WITH DATA
in thread BASIC MATH WITH DATA
Lights are flashing on my machine.... files are poping on the screen.... this is good.... but what am I missing .... all the values read "0" I have run this script through the Perl Builder debugger and it does not indicate errors...which is too bad. There are obviously still some errors in here. Would someone please have a look.... Thanks 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; #my @tmp = split /:/, $lines[-1]; these two go together #my $last = $tmp[3]; as an alternate way of doing this + routine # learn this in next attempt while (<IN>) { 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 my $last = (split /:/, $lines[-1])[3]; $text = "Average of column 3 for the last " . scalar(@lines) . " days: $average\n"; + $last ="Last value in Col3" . scalar(@lines) . " value: $last\n"; print OUT "$text\n"; print OUT "$last\n"; close IN; close OUT ; <\code> The message in the log file reads..... <code> Average of column 3 for the last 0 days: 0 Last value in Col30 value:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re3: BASIC MATH WITH DATA
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 |