#!/usr/bin/perl

print "Content-type:text/plain\n\n";
# assign file handler for myprog
$outfile = 'datafile.txt';      # name file we're printing output to
open(INFO,'>' . $outfile);           # open file for output
print "first\n";
print "just before input file declared";
# assign input file handler
$infile = 'datafile.txt';       # name file to open for inputi

open(INFO, '<' . $infile);            # open file for input
@rands = <INFO>;                # put all the data from file into an array
print "before print rands\n";
print @rands;                   # print the array to get the contents of file
print "after print rand\n";
$j = 1;         # counter for averaging
$sum = 0;       # keeps up with final sum
foreach $number (@rands)        # loop through data to get the average
{
        $sum = $sum + $number;
print $number;
print '\n';
        $j++;
}

$average = $sum / $j;   # calculate average
print "$average\n";     # print new average to the screen
