Search code examples
perldistinct-values

0, 0e0, 0.0, -0, +0, 000 all mean the same thing to Perl, why?


Just puzzling to me.

Related, but different question: What does “0 but true” mean in Perl?


Solution

  • Perl doesn't distinguish kinds of numbers. Looking at all of those with a non-CS/programmer eye, they all mean the same thing to me as well: zero. (This is one of the foundations of Perl: it tries to work like people, not like computers. "If it looks like a duck....")

    So, if you use them as numbers, they're all the same thing. If you use them as strings, they differ. This does lead to situations where you may need to force one interpretation ("0 but true"; see also "nancy typing"). but by and large it "does the right thing" automatically.