]> git.donarmstrong.com Git - infobot.git/commitdiff
* Merged propsed dpkg branch -r1581 Units patch to trunk
authordjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 19 Oct 2007 20:20:18 +0000 (20:20 +0000)
committerdjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 19 Oct 2007 20:20:18 +0000 (20:20 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1582 c11ca15a-4712-0410-83d8-924469b57eb5

src/Modules/Units.pl [new file with mode: 0644]

diff --git a/src/Modules/Units.pl b/src/Modules/Units.pl
new file mode 100644 (file)
index 0000000..7763fd4
--- /dev/null
@@ -0,0 +1,31 @@
+#   Units.pl: convert units of measurement
+#     Author: M-J. Dominus (mjd-perl-units-id-iut+buobvys+@plover.com)
+#    License: GPL, Copyright (C) 1996,1999
+#       NOTE: Integrated into blootbot by xk.
+
+package Units;
+
+#use strict;   # TODO
+
+
+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;
+}
+
+
+1;