Perl doesn’t have boolean type. It will recognise the value from other types to determine whether it is false. The following values are considered false in Perl, other than that, all possible values are considered true:
- ““, “0” (string)
- 0 (integer)
- 0.0 (float)
- a zero sized array
- an empty list
-
undef
(means undefined)
Note: If the subroutine (sub
) doesn’t return a value such as the following, then Perl will think that it is returning a false value due to #Autovivification. Which type of the value should it return is depending on where does the value is being used.
sub emptyReturn {
return; # return either "", "0", 0, 0.0 or undef
}
Perl treat different types differently regarding their booleaness. It is recommended to do a #Perl Type Conversion if necessary.
Note: Built-in Perl functions that return boolean will return integer 1 for true and an empty string (““) for false.