Perl Learning Experience (note)

Source: Internet
Author: User
Tags arithmetic operators

To include double quotes or backslashes in the string, add a backslash before it, and the backslash can also cancel the variable substitution

Single quotes another feature that can span multiple lines, such as:
$text = ' This is two
Lines of text
';
is equivalent to the following sentence:
$text = "This is two/nlines of text/n";


In Perl, all simple variables have the default initial value: "", which is the null character.

Conversion of strings and values
Example 1:
$string = "43";
$number = 28;
$result = $string + $number; # $result = 71
If the string contains non-numeric characters, it starts from left to the first non-numeric character, such as:
$result = "Hello" * 5; # $result = 0
$result = "12a34" +1; # $result = 13

Arithmetic operators: + (plus),-(minus), * (multiply),/(except), * * (Power),% (take more),-(Monocular negative)
(1) The cardinality of the power can not be negative, such as ( -5) * * 2.5 # error;
(2) The result of power can not exceed the limit of computer expression, such as 999999 # error
(3) The operand of the remainder, if not an integer, rounded to an integer; the right-hand side of the operator cannot be zero
(4) Monocular negative can be used for variables:-$y; # equivalent to $y *-1

The operator <=> result is:
0-Two values equal
1-The first value is large
-1-The second value is large

string comparison operator

string comparison operator

Operator Describe  
Lt Less than  
Gt Greater than  
eq Equals  
Le Less than or equal to  
Ge Greater than or equal to  
Ne Not equal to  
Cmp Compare, return 1, 0, or-1  

Logical XOR OR: $a xor $b
Bitwise XOR OR: ^
Bit and:& Note: Do not use & for negative integers, because Perl will convert them to unsigned numbers. #。。


In Perl, + + can be used for strings, but when the end character is ' z ', ' z ', ' 9 '

Do not use--,perl will first convert the string to a number and then subtract from it
$stringvar = "ABC";
$stringvar--; # $stringvar =-1 now

If the string contains a non-alphanumeric character, or the number is in the letter, the value of the + + operation is converted to a numeric zero, so the result is 1


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.