在我的代码中,当我在输入中输入一些非数字字母(即$temp
)时,它以“太冷!”作出响应。而不是“无效”。我错过了什么?IF语句意外的结果:“string”<= 72是真的?
#!/usr/bin/perl
print "What is the temperature outside? ";
$temp=<>;
if ($temp > 72) {
print "Too hot!\n"; }
elsif ($temp <= 72) {
print "Too cold!\n"; }
else {
print "Temperature $temp is invalid.\n"; }
Perl是这方面的“弱类型”语言。操作人员要小心,以免受到强制(如此!)咬。 – 2011-12-12 02:49:47