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

前端 未结 5 1299
谎友^
谎友^ 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:41

    Here is how I got around the problem:

    my $res = ($a eq $b) *1;
    

    The *1 converts the boolean resulting from ($a eq $b) into a scalar.

提交回复
热议问题