Monks,

I've been agonizing over this problem for a while...

I have this database and I need to calculate the average of the values in a particular column (that value is $temp1[38] in my array). The calculation of the average depends on one criteria;

for all the rows if $temp1[36] = "In Production";

then I would take those rows $temp1[38] values and calculate their average. Does that make sense?


Here's my code so far:

#!/usr/local/bin/perl5 print "Content-type: text/html\n\n"; open(HANDLE,"script_integration_records"); while (<HANDLE>) { @temp1 = split(/:/); $domain = unpack ("A4", $temp1[40]); if ($domain eq "ATM") { if ($temp1[36] eq "In Production") { print "$temp1[38]\n"; # This is my break point...I think here's +where I need help } } } close(HANDLE);


The output of this code works, but it just does prints out a list of values that is in the array I have...the values are correct, I just need to take those values and find their average. Here's the output:

34 114 123 2 5 48 71 67 71

Thanks so much for enlightening me!

In reply to Calculating the average of a column in a flat-file database by suggus

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.