Can someone explain what exactly the string ‘0 but true’ means in Perl? As far as I understand, it equals zero in an integer comparison, but evaluates to true when used as a boolean. Is this correct? Is this a normal behavior of the language or is this a special string treated as a special case in the interpreter?
Share
It’s normal behaviour of the language. Quoting the
perlsynmanpage:Because of this, there needs to be a way to return
0from a system call that expects to return0as a (successful) return value, and leave a way to signal a failure case by actually returning a false value.'0 but true'serves that purpose.