我在Perl中有这样的问题: 要编写一个Perl脚本,它会询问用户温度,然后询问是否将其转换为度数Celius或华氏度。执行转换并显示答案。对于温度转换的公式为:Perl华氏转换为摄氏温度,反之亦然
1) Celsius to Fahrenheit:C=(F-32) x 5/9
2) Fahrenheit to Celsius:F=9C/5 + 32
我的脚本是:
#!/usr/bin/perl
use strict;
use warnings;
print "Enter the temperature: ";
my $temp = <STDIN>;
print "Enter the Conversion to be performed:";
my $conv = <STDIN>;
my $cel;
my $fah;
if ($conv eq 'F-C') {
$cel = ($temp - 32) * 5/9;
print "Temperature from $fah degree Fahrenheit is $cel degree Celsius";
}
if ($conv eq 'C-F') {
$fah = (9 * $temp/5) + 32;
print "Temperature from $cel degree Celsius is $fah degree Fahrenheit";
}
我从键盘输入$ TEMP和$ CONV后,空白输出将appear.Where我该怎么错了?请帮忙。提前致谢。
如果其他人正在寻找它:有一个CPAN模块可以做到这一点:[Convert :: Temperature](https://metacpan.org/module/Convert::Temperature) – simbabque