0
在下面的Perl程序中,由於某種原因,整數部分不會發生。相反,控制檯輸出兩個整數的連接,也不會發生divsion的if語句。爲什麼是這樣?謝謝。在我的代碼中使用Perl進行整數部分不起作用
代碼:
print "Please Enter Your First Number\n";
$num1 = <>; chomp $num1;
print "Please Enter Your Operation\n";
$operation = <>; chomp $operation;
print "Please Enter Your Second Number\n";
$num2 = <>; chomp $num2;
if ($operation == "+"){
$result = $num1 + $num2;
} elsif ($operation == "-"){
$result = $num1 - $num2;
} elsif ($operation == "*"){
$result = $num1 * $num2;
#Problem HERE:
} elsif ($operation == "/"){
if ($num2 == 0){
print "Cant Divide be Zero Mate\n";
} else {
$result = $num1/$num2;
}
}
print "\n";
print "result of $num1 $operation $num2 = $result";
我是新來的Perl中,可以ü用一個例子提供? – KingMak
哦是eq字符串比較和==數字比較? – KingMak
@KingMak Yep,就是這樣 - 字符串爲'eq',數字爲'=='。 –