我在 Perl 中有一个问题:编写一个 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 后,会出现空白输出。我哪里出错了?请帮忙。提前致谢。