From 03c07114f2e65815bb4efef0fc9c1579edc74e54 Mon Sep 17 00:00:00 2001 From: djmcgrath Date: Fri, 19 Oct 2007 20:20:18 +0000 Subject: [PATCH] * Merged propsed dpkg branch -r1581 Units patch to trunk git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1582 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/Modules/Units.pl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Modules/Units.pl diff --git a/src/Modules/Units.pl b/src/Modules/Units.pl new file mode 100644 index 0000000..7763fd4 --- /dev/null +++ b/src/Modules/Units.pl @@ -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; -- 2.39.5