OK....This is almost there..... thanks for the <IN> tip.... it looked like a small correction... it's gotta be in there... thanks
#!/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" 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

In reply to Re: Re: Re: Re: BASIC MATH WITH DATA by joachim
in thread BASIC MATH WITH DATA by joachim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.