tye...... thank you for having a look. I can see that you
trying to get the data to dump.... I tried your line entry
and ..... nothing dumped .... in short the code is running
but not doing the calculation.
As for data...... I am trying to do the calculation for a
10 entry average.... the test file is 31Kb of data.... more
than sufficient for this small program. We should be able
to get a 200 event average with that amount of data.
#!/usr/bin/perl -w
use strict;
$my infile = shift;
$my outfile = shift;
open(IN, $infile) || die("Can't open input file $infile - $!");
open(OUT, ">$outfile") || die("Can't open output file $outfile
+- $!");
my $text;
my $text2;
my @lines;
while (<IN>) {
push @lines;
shift @lines if @lines > 10;
}
chomp(@lines);
my @cols;
my $total = 0;
for (@lines) {
@cols = split /:/;
print "($cols[3]) $_";
$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";
+
$text2 ="Last value in Col3 " .
scalar(@lines) . " $last\n";
print OUT "$text\n";
print OUT "$text2\n";
close IN;
close OUT ;
**** this is the best edited version till now.... have a
look..... it would be easy to give up in frustration....
it's being able to do caculations like this .... is what
scripting is all about... for me anyway. Especially when
you can see ways of doing the work faster and simpler than
in Excel .... once you get it coded right that is..
Joachim
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.