Deep research on true and false in Perl

Source: Internet
Author: User

Deep research on true and false in Perl

This article mainly introduces the in-depth study of true and false values in Perl. This article details the differences between true and false values in Perl. For more information, see

Perl deems the true value self-evident, indicating that the true value of any thing can be calculated. Perl defines the true value in a practical way, that is, the true value of an object depends on the object type. Perl is always optimistic that there are more real things in the world than fake things.

The difference between Perl and any other computer language is that Perl is created by the linguistics, and the meaning of the language is inseparable from the context, therefore, the true values in Perl can all be scalar (the scalar $ and array @ are similar to the singular and plural values in English. The difference between book and books is that the true values in the real world should be singular values, therefore, it is a scalar). In addition, it does not perform any type of forced conversion (for example, int ('42') in Python to convert the numeric type to the int type, in Java, (int) 'D' converts the struct type to an integer type ).

For values of various types in a scalar, the rules are as follows:

Character Type: All characters except "" and "0" are true)

Numeric: All digits except 0 are true.

Reference Type: All references are true (all references point to an object with an address, which is definitely not 0, because it must have been defined)

Undefined: all undefined values are false.

The following example shows the true and false concepts in Perl:

The Code is as follows:

0 # convert to string "0", so it is false

1 # convert to string "1", so it is true

100-100 #100-100 equals 0, which is converted to the string "0", so false

0.00 # equal to 0, will be converted to the string "0", so it is false

"0" # string "0", so false

"" # This is an empty string, so it is false.

"0.00" # It is neither "" nor "0", so it is true

"0.00" + 0 # forced conversion from +, the calculation result is 0, so it is false

\ $ A # reference of scalar $ a, so it is true, even if $ a is false.

Undef () # is a function that returns undefined values, so it is false.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.