]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Units.pl
more bloot refs
[infobot.git] / src / Modules / Units.pl
1 #   Units.pl: convert units of measurement
2 #     Author: M-J. Dominus (mjd-perl-units-id-iut+buobvys+@plover.com)
3 #    License: GPL, Copyright (C) 1996,1999
4 #       NOTE: Integrated into infobot by xk.
5
6 package Units;
7
8 #use strict;    # TODO
9
10
11 sub convertUnits {
12   my ($from,$to) = @_;
13
14   if ($from =~ /([+-]?[\d\.]+(?:e[+-]?[\d]+)?)\s+(temp[CFK])/){
15     $from = qq|${2}(${1})|;
16   }
17
18   my $units = new IO::File;
19   open $units, '-|', 'units', $from, $to or &::DEBUG("Unable to run units: $!") and return;
20   my $response = readline ($units);
21   if ($response =~ /\s+\*\s+([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/ or $response =~ /\t([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/){
22     &::performStrictReply(sprintf("$from is approximately \002%.6g\002 $to", $1));
23   }
24   else {
25     &::performStrictReply("$from cannot be converted to ${to}: $response");
26   }
27   return;
28 }
29
30
31 1;
32
33 # vim:ts=4:sw=4:expandtab:tw=80