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.
11 my ( $from, $to ) = @_;
13 if ( $from =~ /([+-]?[\d\.]+(?:e[+-]?[\d]+)?)\s+(temp[CFK])/ ) {
14 $from = qq|${2}(${1})|;
17 my $units = new IO::File;
18 open $units, '-|', 'units', $from, $to
19 or &::DEBUG("Unable to run units: $!")
21 my $response = readline($units);
22 if ( $response =~ /\s+\*\s+([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/
23 or $response =~ /\t([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/ )
25 &::performStrictReply(
26 sprintf( "$from is approximately \002%.6g\002 $to", $1 ) );
29 &::performStrictReply("$from cannot be converted to ${to}: $response");
36 # vim:ts=4:sw=4:expandtab:tw=80