summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-03-11 12:55:03 +0100
committerDaniel Friesel <derf@finalrewind.org>2015-03-11 12:55:03 +0100
commit2ce07a807ab533107a2b1b8b05c062aec0afae66 (patch)
tree05a46b32d32c52614892636f4a9b44e14f61ee7c /index.pl
parent2e1e0373c4d678bd7300e8b9cdc12de83b1cefe5 (diff)
toplist: handle empty list result (fix division by zero)
Diffstat (limited to 'index.pl')
-rw-r--r--index.pl17
1 files changed, 10 insertions, 7 deletions
diff --git a/index.pl b/index.pl
index 6a7805f..9ae057d 100644
--- a/index.pl
+++ b/index.pl
@@ -512,13 +512,16 @@ get '/top' => sub {
}
my @argsort = reverse sort { $rates[$a] <=> $rates[$b] } ( 1 .. 99 );
- my @toplist = map {
- [
- $translation{$_} // $_,
- sprintf( '%.2f%%', $rates[$_] * 100 / $total ),
- $rates[$_]
- ]
- } @argsort;
+ my @toplist;
+ if ( $total > 0 ) {
+ @toplist = map {
+ [
+ $translation{$_} // $_,
+ sprintf( '%.2f%%', $rates[$_] * 100 / $total ),
+ $rates[$_]
+ ]
+ } @argsort;
+ }
$self->render(
'toplist',