A deep study of truth and Sham in Perl

Source: Internet
Author: User
Tags scalar in python

This article mainly introduces the true and false in-depth study in Perl, this article explains in detail the difference between the truth value and the false values in Perl, the need of friends can refer to the

Perl considers truth values to be self-evident (self-evident), which means that the truth of any thing can be computed. Perl defines truth values in a practical way, that is, the truth of an entity depends on the type of the entity. Perl is always optimistic that there are more real things in this world than fake things.

Perl differs from any other computer language, Perl is created by linguists, and the language's meaning is inseparable from context, so the true value of Perl can be in scalar (scalar $ and array @ similar to the singular and plural in English, the difference between book and books, the truth value in the real world, It should be singular, so it is scalar), and in addition, no casts of any kind (for example, int (' 42 ') in Python will convert the character type int with a number to the type int., in Java (int) ' d ' converts the character type to an integral type).

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

Character type: All characters are true except "" and "0" (true)

Digital type: Except 0, all numbers are true

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

Undefined: All undefined values are false

The following example is a good understanding of the true and False concepts in Perl:

The code is as follows:

0 # will be converted to the string "0", so false

1 # will be converted to the string ' 1 ', so true

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

0.00 # equals 0, converts to string ' 0 ', so false

"0" # string "0", so false

"" # This is an empty string, so for false

"0.00" # is not "", and is not "0", so true

"0.00" + 0 # Cast by +, evaluates to 0, so false

$a # A reference to a scalar $a, so true, even if $a is false.

Undef () # is a function that returns an undefined value, so false

Related Article

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.