When does the difference between a string and a number matter in Perl 5?

后端 未结 4 1746
逝去的感伤
逝去的感伤 2020-12-17 19:30

If a string in Perl 5 passes looks_like_number, it might as well be a number. For instance,

my $s = \"10\" + 5;

results in $s

4条回答
  •  清酒与你
    2020-12-17 20:13

    I can only think of one: when checking for truth. Strings that are equivalent to 0, but that are not "0", such as "0.0", "0 but true", "0e0", etc. all pass looks_like_number and evaluate to 0 in numeric context, but are still considered true values.

提交回复
热议问题