#!/usr/bin/perl use strict; use warnings; print "\nMean Average Program\n\nenter values, when done enter 'done':"; my @value; while (my $input=<>){ chomp $input; last if uc($input) eq "DONE"; #Validate that the input is only digits-should reallly [use Scalar::Util qw(looks_like_number)] print ("INVALID value '$input' -ignored\nTry again:") , next unless $input =~ /^[+-]?\d+(\.\d+)?$/; # Crude floating-point test push @value, $input ; print "Enter a value('done' if finished): "; } my $mean = 0; for my $val (@value){ $mean += $val; } if (scalar @value){ # There is at least one @value - avoid div by 0 $mean = $mean / scalar(@value); } print "\nThe mean of your values is $mean\n";