From 0f421fbf603b2427a6c010cdd375bf40b3aacabb Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Thu, 24 Nov 2011 11:28:52 +0100 Subject: use max index instead of count ... then it all works nicely --- lib/Smokeping/matchers/Median.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/Smokeping') diff --git a/lib/Smokeping/matchers/Median.pm b/lib/Smokeping/matchers/Median.pm index 2c721bf..3973b7f 100644 --- a/lib/Smokeping/matchers/Median.pm +++ b/lib/Smokeping/matchers/Median.pm @@ -95,8 +95,7 @@ sub Test($$) sub robust_median(@){ my @numbers = sort {$a <=> $b} grep { defined $_ and $_ =~ /\d/ } @_; - my $count = scalar @numbers; - return 0 if $count == 0; - $count--; # we are 0 based + my $count = $#numbers; + return 0 if $count < 0; return ($count / 2 == int($count/2)) ? $numbers[$count/2] : ($numbers[$count/2+0.5] + $numbers[$count/2-0.5])/2; } -- cgit v1.2.3-24-g4f1b