I'm trying to figure this out but my $average is not calculating right.
My $filesize is supposed to add into my $totalFileSize after every iteration. Then $totalFileSize is supposed to be divided by $count and that NUMBER is supposed to equal $average.
Here is my code and the output I get.
-----------------------------------------------------------
-----------------------------------------------------
OUTPUT
My $filesize is supposed to add into my $totalFileSize after every iteration. Then $totalFileSize is supposed to be divided by $count and that NUMBER is supposed to equal $average.
Here is my code and the output I get.
-----------------------------------------------------------
Code:
#!/usr/bin/perl
open (ALBERT_LAB, "Lab3.txt") or die ("Cannot open file");
while(<ALBERT_LAB>)
{
chomp;
($date, $time, $ampm, $filesize, $filename) = split(" ");
print ("$filesize\t\t$filename\n");
$count++;
$totalFileSize+=$filesize;
}
$average = $totalFileSize/$count;
print("\nTotal Files: $count \tAverage file size: $average\n");
close(ALBERT_LAB);
OUTPUT
Code:
1,572,727,014 IN11-135.E01 1,223 IN11-135.E01.txt 1,572,694,696 IN11-135.E02 1,572,740,428 IN11-135.E03 1,572,785,002 IN11-135.E04 1,572,696,748 IN11-135.E05 1,572,745,871 IN11-135.E06 1,572,737,726 IN11-135.E07 1,572,785,459 IN11-135.E08 1,572,777,135 IN11-135.E09 1,572,751,922 IN11-135.E10 1,572,684,462 IN11-135.E11 1,556,456,660 IN11-135.E12 Total Files: 13 Average file size: 1
Comment