我来自C++的背景,并试图用Perl开始学习Perl。然而,这段代码在第二章中已经留下了困惑:为什么不2 == 4返回false?
#!/usr/bin/perl
use warnings;
print"Is two equal to four? ", 2 == 4, "\n";
当我运行的代码,这是输出:
Is two equal to four?
这在下文中进一步解释说,2 ==价值4是不确定的,但这对我来说似乎令人困惑和反直觉。两个显然不等于四,并且4和4之间的相同比较将产生真实,导致在输出结束时产生'1'。为什么表达式不会返回false?
Perl6在bool主题中更直观http://faq.perl6.org/ – teodozjan
'2 == 4? '是':'不' – ikegami
另请参见[错误的定义](http://stackoverflow.com/questions/1036347/how-do-i-use-boolean-variables-in-perl/5655485#5655485) – ikegami