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