#!/usr/bin/perl -w $infile = shift; $outfile = shift; open(IN, $infile) || die("Can't open input file $infile - $!"); open(OUT, ">$outfile") || die("Can't open output file $outfile - $!"); use strict; my $text; my @lines; while (<>) { push @lines; shift @lines if @lines > 10; } chomp(@lines); my @cols; my $total = 0; for (@lines) { @cols = split /:/; $total += $cols[3]; } my $average = $total / (@lines || 1); # if no lines, avoid division by zero ***** error here***** $text= "Average of column 3 for the last " ;#, scalar(@lines)," days: $average\n"; print OUT "$text\n"; close IN; close OUT ;