]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Math.pl
- strictify
[infobot.git] / src / Modules / Math.pl
index b7ba1568712a27c119f13344fe66d383aeed0a19..1e23177a79229a0e80587505984d55de08b588f5 100644 (file)
@@ -2,7 +2,9 @@
 # infobot copyright (C) kevin lenzo 1997-98
 #
 
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw($message);
 
 my %digits = (
        "first",   "1",
@@ -101,31 +103,36 @@ sub perlMath {
     if (($locMsg =~ /^\s*[-\d*+\s()\/^\.\|\&\*\!]+\s*$/)
        && ($locMsg !~ /^\s*\(?\d+\.?\d*\)?\s*$/)
        && ($locMsg !~ /^\s*$/)
-       && ($locMsg !~ /^\s*[( )]+\s*$/))
-    {
+       && ($locMsg !~ /^\s*[( )]+\s*$/)
+       && ($locMsg =~ /\d+/)
+    ) {
+       $locMsg =~ s/([0-9]+\.[0-9]+(\.[0-9]+)+)/"$1"/g;
        $locMsg = eval($locMsg);
 
        if (defined $locMsg and $locMsg =~ /^[-+\de\.]+$/) {
            $locMsg = sprintf("%1.12f", $locMsg);
            $locMsg =~ s/\.?0+$//;
 
-           if (length($locMsg) > 30) {
+           if (length $locMsg > 30) {
                $locMsg = "a number with quite a few digits...";
            }
        } else {
            if (defined $locMsg) {
                &DEBUG("math: locMsg => '$locMsg'... FIXME");
            } else {
-               $locMsg = "undefined";
+               &status("math: could not really compute.");
+               $locMsg = "";
            }
        }
     } else {
        $locMsg = "";
     }
 
-    if ($locMsg ne $message) {
+    if (defined $locMsg and $locMsg ne $message) {
+       # success.
        return $locMsg;
     } else {
+       # no match.
        return '';
     }
 }