Perl considers truth values to be self-evident (self-evident), which means that the truth of any thing can be computed. Perl defines truth values in a practical way, that is, the truth of an entity depends on the type of the entity. Perl is always optimistic that there are more real things in this world than fake things.
Perl differs from any other computer language, Perl is created by linguists, and the language's meaning is inseparable from context, so the true value of Perl can be in scalar (scalar $ and array @ similar to the singular and plural in English, the difference between book and books, the truth value in the real world, It should be singular, so it is scalar), and in addition, no casts of any kind (for example, int (' 42 ') in Python will convert the character type int with a number to the type int., in Java (int) ' d ' converts the character type to an integral type).
For values of various types in a scalar, the rules are as follows:
Character type: All characters are true except "" and "0" (true)
Digital type: Except 0, all numbers are true
Reference type: All references are true (all references will point to an object with an address, which is definitely not 0 because it is definitely defined)
Undefined: All undefined values are false
The following example is a good understanding of the true and False concepts in Perl:
Copy Code code as follows:
0 # will be converted to the string "0", so false
1 # will be converted to the string ' 1 ', so true
100-100 # 100-100 equals 0, which translates to the string "0", so false
0.00 # equals 0, converts to string ' 0 ', so false
"0" # string "0", so false
"" # This is an empty string, so for false
"0.00" # is not "", and is not "0", so true
"0.00" + 0 # Cast by +, evaluates to 0, so false
\ $a # A reference to a scalar $a, so true, even if $a is false.
Undef () # is a function that returns an undefined value, so false