]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Units.pl
more binmode attempts
[infobot.git] / src / Modules / Units.pl
index 1f2fec5fa7a8780eaec2b52a4bc44b9eb8f99343..79e50b3aed777b6a79475ab03a9a0376af173151 100644 (file)
@@ -5,29 +5,32 @@
 
 package Units;
 
-#use strict;   # TODO
-
+use strict;
 
 sub convertUnits {
-  my ($from,$to) = @_;
-
-  if ($from =~ /([+-]?[\d\.]+(?:e[+-]?[\d]+)?)\s+(temp[CFK])/){
-    $from = qq|${2}(${1})|;
-  }
-
-  my $units = new IO::File;
-  open $units, '-|', 'units', $from, $to or &::DEBUG("Unable to run units: $!") and return;
-  my $response = readline ($units);
-  if ($response =~ /\s+\*\s+([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/ or $response =~ /\t([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/){
-    &::performStrictReply(sprintf("$from is approximately \002%.6g\002 $to", $1));
-  }
-  else {
-    &::performStrictReply("$from cannot be converted to ${to}: $response");
-  }
-  return;
+    my ( $from, $to ) = @_;
+
+    if ( $from =~ /([+-]?[\d\.]+(?:e[+-]?[\d]+)?)\s+(temp[CFK])/ ) {
+        $from = qq|${2}(${1})|;
+    }
+
+    my $units = new IO::File;
+    open $units, '-|', 'units', $from, $to
+      or &::DEBUG("Unable to run units: $!")
+      and return;
+    my $response = readline($units);
+    if (   $response =~ /\s+\*\s+([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/
+        or $response =~ /\t([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/ )
+    {
+        &::performStrictReply(
+            sprintf( "$from is approximately \002%.6g\002 $to", $1 ) );
+    }
+    else {
+        &::performStrictReply("$from cannot be converted to ${to}: $response");
+    }
+    return;
 }
 
-
 1;
 
 # vim:ts=4:sw=4:expandtab:tw=80