Why does Perl use the empty string to represent the boolean false value?

前端 未结 5 1297
谎友^
谎友^ 2020-12-06 05:04

When evaluating an expression in a scalar (boolean) context, Perl uses the explicit value 1 as a result if the expression evaluates to true and the empty string

5条回答
  •  误落风尘
    2020-12-06 05:50

    Both number 0 and empty string ultimately evaluate as false in Perl. I think this is a matter of language design. When writing your own code, you can of course assume any which one false encoding convention.

    For further details, check out "How do I use boolean variables in Perl?".

提交回复
热议问题