# Operators in the Perl language

Source: Internet
Author: User

One, arithmetic operators: + (plus),-(minus), * (multiply),/(except), * * (UP),% (remainder),-(Monocular negative)

(1) The base of the exponentiation can not be negative, such as ( -5) * * 2.5 # error;
(2) The result of a exponentiation cannot exceed the limit indicated by the computer, such as the 999999 # error
(3) The operand of the remainder, if not an integer, is rounded to an integer and the operator to the right cannot be zero
(4) Monocular negative can be used for variables:-\$y; # equivalent to \$y *-1
(5) corresponding to + =,-=, *=,/=, **=,%=

Second, integer comparison operators

Table 1. Integer comparison Operators

 Operator Describe < Less than > Greater than == Equals <= Less than or equal >= Greater than or equal != Not equal to <=> Compare, return 1, 0,-1

The operators <=> results are:
0-Two values equal
1-Large first value
1-Large second value

Three, string comparison operators

Table 2. string comparison operators
 Operator Describe Lt Less than Gt Greater than eq Equals Le Less than or equal Ge Greater than or equal Ne Not equal to Cmp Compare, return 1, 0, or-1

Four, logical operators

Logic or: \$a | | \$b or \$a or \$b
Logic with: \$a && \$b or \$a and \$b
Logical non-:! \$a or not \$a
Logical XOR: \$a XOR \$b

Five, bitwise operators

Bits and:&
Bit or: |
Bit non: ~
Bit XOR: ^
Shift Left: \$x << 1
Shift Right: \$x >> 2
Note: Do not use & for negative integers, because Perl will convert them to unsigned numbers.

Six, assignment operators

Table 3. Assignment operators

 Operator Describe = Assignment only += Addition and assignment -= Subtraction and assignment *= Multiplication and assignment /= Division and Assignment %= Remainder and assignment **= Exponentiation and Assignment &= Bitwise and and assignment |= Bitwise OR and Assignment ^= Bitwise XOR and Assignment

Table 4. Assignment operator Examples

 An expression An equivalent expression \$a = 1; None (Basic Assignment) \$a-= 1; \$a = \$a-1; \$a *= 2; \$a = \$a * 2; \$a/= 2; \$a = \$a/2; \$a%= 2; \$a = \$a% 2; \$a **= 2; \$a = \$a * * 2; \$a &= 2; \$a = \$a & 2; \$a |= 2; \$a = \$a | 2; \$a ^= 2; \$a = \$a ^ 2;

Note:
1. = can occur multiple times in an assignment statement, such as:
\$value 1 = \$value 2 = "a string";
2. = as a sub-expression
(\$a = \$b) + = 3;
Equivalent to
\$a = \$b;
Related Keywords:
Related Article

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.