in reply to Re^3: Basic math with Data
in thread BASIC MATH WITH DATA

OK....This is almost there..... thanks for the "IN" tip.... it looked like a small correction... it's gotta be in there. .... thanks ... only one small problem... it's not doing the "OUTPUT" unfortunately.... please have a look.....
#!/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:
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" or are " " blank 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

Replies are listed 'Best First'.
Re^5: Basic math with Data
by lemming (Priest) on Jan 26, 2001 at 03:44 UTC
Re: Re: Re: Re: Re: Basic math with Data
by chipmunk (Parson) on Jan 26, 2001 at 03:45 UTC
    This is my fault. The line: push @rows; should be: push @rows, $_; I always forget that $_ is not the default argument for push.

    I've updated the original code to correct my error.