http://qs321.pair.com?node_id=1160137


in reply to Re^6: The True but Zero value?
in thread The True but Zero value?

I should have mentioned in my original post that there is another set of special cases for this purpose. Perl silently ignores leading and trailing whitespace when numifying a string (which AFAIK is not widely known nor documented, although a pointer to the relevant docs are welcome). So there are an infinite set of strings which are false numerically, but true in boolean context. (And an infinite set of strings which are numerically equivalent to any integer you choose.)

perl -wle'my $n= (" " x 1_000_000) . "0" . (" " x 1_000_000); print $n + ? "true" : "false", " as a bool, prenumification"; print 0+$n ? "tru +e" : "false", " as a bool, numified"; print $n ? "true" : "false", " +as a bool, postnumification";' true as a bool, prenumification false as a bool, numified true as a bool, postnumification

This is not generally a problem except for people who write serializers and need to ensure that " 0 " round trips correctly.

---
$world=~s/war/peace/g