Why is '0' false in Perl?

后端 未结 6 1796
故里飘歌
故里飘歌 2021-01-05 02:14

First of all, I come from C, Java, Python background. Recently, I started learning Perl for my new job and I got curious about \'0\' (0-string) being false.

6条回答
  •  灰色年华
    2021-01-05 02:32

    0 equates to false in C, as well - it equates to false in several "legacy" programming languages, perhaps due to 0's inherent tie to binary and circuits, where 0 can mean "no charge".

    In any case, newer languages often inherit behaviors and interpretations of languages before. The binary meaning of 0 being "no charge" or "it is false that there is a charge" has been long since abstracted out of any high-level programming language, but the tidbit of semantic still remains even through the most modern programming languages.

    Also - to the best of my knowledge, it has nothing to do with <> - where did you read that?

提交回复
热议问题