Possible Duplicate:
How do I use boolean variables in Perl?
[root@ ~]$ perl -e 'if(true){print 1}'
1
[root@ ~]$ perl -e 'if(false){print 1}'
1
I'm astonished both true
and false
passes the if
...
In most of the programming language True and False are considered as the boolean values. But Perl does not provide the type boolean for True and False. In general, a programmer can use the term “boolean” when a function returns either True or False.
Perl does not have a special boolean type and yet, in the documentation of Perl you can often see that a function returns a "Boolean" value. Sometimes the documentation says the function returns true or returns false.
What is true/false in Perl. In short, the following elements evalue to false in Perl: The number zero (0) means false. The string zero ('0' or "0") means false.
Always use warnings, especially on one-liners.
Perl has no true or false named constants, and without warnings or strict enabled, a "bareword" (something that could be a constant or function but isn't) is silently interpreted as a string. So you are doing if("true")
and if("false")
, and all strings other than ""
or "0"
are true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With