Просмотр исходного кода

Don't keep a huge hash of sayings and choose one, rather randomly update to a new saying... lowers memory usage and should help allow us to make a modular version

sbingner 25 лет назад
Родитель
Сommit
283713a7ef
1 измененных файлов с 5 добавлено и 4 удалено
  1. 5 4
      pisg.pl

+ 5 - 4
pisg.pl

@@ -494,8 +494,10 @@ sub parse_file
                     my $l = length($saying);
 
                     if ($l > $conf->{minquote} && $l < $conf->{maxquote}) {
-                        # Creates $hash{nick}[n] - a hash of an array.
-                        push (@{ $sayings{$nick} }, $saying);
+                        # Creates $hash{nick}
+                        if (!(defined $sayings{$nick}) || (rand($longlines{$nick} + 50) < 15)) {
+                            $sayings{$nick} = $saying;
+                        }
                         $longlines{$nick}++;
                     }
 
@@ -1033,8 +1035,7 @@ sub activenicks
         if (!$longlines{$nick}) {
             $randomline = "";
         } else {
-            my $rand = rand($longlines{$nick});
-            $randomline = htmlentities($sayings{$nick}[$rand]);
+            $randomline = htmlentities($sayings{$nick});
         }
 
         # Convert URLs and e-mail addys to links