don't try to add non-numbers (particularly since will break the

average calcualtion), but do warn about them.
This commit is contained in:
Tim Connors 2021-12-06 22:31:37 +11:00
parent a45d13b353
commit 11bd6fa398

View file

@ -42,6 +42,15 @@ my $lastfan;
my $print_stats = 1;
sub is_num {
my ($val) = @_;
if ( $val =~ /^[-+]?(\d*\.?\d+|\d+\.?\d*)+$/ ) {
return 1;
}
print "is_num($val)=0\n" if !$quiet;
return 0;
}
# returns undef if there are no inputs, and ignores inputs that are
# undef
sub average {
@ -50,7 +59,7 @@ sub average {
my $div = 0;
my $tot = 0;
foreach my $v (@v) {
if (defined $v) {
if (defined $v && is_num($v)) {
$tot += $v;
$div++;
}