in reply to Re: Calculating the average of a column in a flat-file database
in thread Calculating the average of a column in a flat-file database

Masem,

But my main goal is to display the average of that calculation...BTW I'm new to perl.

I have a hard time with loops and I just wanted the script to look through the DB and find the instances of "In Production". With the instances found, I would like to find the average of the values in my array $temp1[38] for the row that contained "In Production" and print out the average.
  • Comment on Re: Re: Calculating the average of a column in a flat-file database
  • Download Code

Replies are listed 'Best First'.
Re3: Calculating the average of a column in a flat-file database
by Hofmator (Curate) on Oct 26, 2001 at 13:03 UTC
    But my main goal is to display the average of that calculation

    Well, that's not hard :) - actually more than trivial, you output values by printing them. So after Masem's code put either one of those

    # with string interpolation print "The average is $average.\n"; # or with string concat print "The average is " . $average . ".\n"; # or with multiple arguments to print print "The average is ", $average, ".\n"; # or using printf and rounding to 2 decimals printf "The average is %.2f.\n", $average;

    I suggest you try to get a good book on perl, e.g. Learning Perl (3rd edition) by our one and only merlyn. Also have a look onto our New Monks Info Page. There you will find lot's of sources of information on perl and tips to get started.

    -- Hofmator