don't try to add non-numbers (particularly since will break the
average calcualtion), but do warn about them.
This commit is contained in:
parent
a45d13b353
commit
11bd6fa398
1 changed files with 10 additions and 1 deletions
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue