Operators (operator)
Other computer languages have operators, Perl is also supported. The operator is used to calculate the operand, in all computer languages, the operator of Perl has a certain advantage.
Perl supports the same set of operators as most other computer languages. Operators allow a computer language to perform actions on operands. As in every computer language, Perl operators also have a certain precedence.
In front, we already know the assignment operator (=). This operator is to assign the value of a variable to another variable:
We've alleady encountered the assignment operator (=). This Operator Assigns a value from one variable to another:
$ String1 = $ String2;
The above code assigns $ String2's value to $ String1.
Now let's take a look at the binary and one yuan arithmetic operator:
The Above Code Assigns The Value of $ String2 To $ String1. We will now consider binary and unary ferrest.
OP1 OP2 Do two values to add OP1 - OP2 to two numerical assumptions OP1 * OP2 Make multiplication operation OP1 / OP2 Multiply OP1 / OP2 Doing OP1% OP2 for two integer values The remaining OP1 XX OP2 Ask Operation: Ask OP1 OP2 Power OP1 Pre-plus Action: The value of the OP1 first increases, then assigns the value to its own OP1 , add operation: OP1 value first assign itself, add value - -OP1 Preferred operation: The value of OP1 is decreased, then assigen a value to its own OP1- and reduced operation: OP1 value is given to itself, then reduce the value
op1 op2 The addition operator will add two numbers op1 -... op2 The subtraction operator will subtract two numbers op1 * op2 The multiplication operator will multiply two numbers op1 / op2 The division operator will divide two numbers op1% op2 The modulus operator. will return the remainder of the division of two integer operands. op1 xx op2 The exponentiation operator will raise op1 to the power of op2. op1 The pre-increpment operator will increase the value of op1 first, then assign it. op1 The post -increment operator will increase the value of op1 after it is assigned. --op1 The pre-decrement operator will decrease the value of op1 before it is assigned. op1-- The post-decrement operator will decrease the value of op1 after it is The logical operator is mainly used to control the runtime process of the program. The logical operators supported by Perl are:
The Logical Operators Are Used Mainly To Control The Flow of The Program. Some of The Logical Operators That Perl Supports include:
&& and operators: only and when both values are TRUE, the return value is true || or operator: only and when at least one value is TRUE, the return value is True! Non-operator: Take a value The reverse op1 == OP2 detects whether the two values are equal to OP1! = OP2 detects whether the two values are not equal to OP1
&& The AND operator takes two values, and will return true only if both values are true. || The OR operator takes two values, and will return true only if at least one value is true.! The NOT operator will negate a value. op1 == op2 The equals operator checks for the equality of two numerical values. op1! = op2 This not-equals operator checks for the inequality of two numerical values. op1
There Are Other Operators Which Can Also Be Used In Perl. We Have The ConcateNation Operator for strings:
$ String1. $ String2
The above code will connect the string $ String1 with $ String2 to form a new string. The Above Code Will Concatenate $ String1 With $ String2 To Form A New String.
We can also specify a string several times with a cyclic operator (x):
We Also Have The Repetition Operator (x) This Operator Will Repeat A String a Certain Number of Times Specified:
$ String1 x 2;
The above code will repeat the string $ String1 twice.
The Above Code Will Repeat $ String1 TWICE.
We can also specify a range of arrays with the following operations:
The Range Operator Allows US To Use Ranges, in Arrays Or Patters:
@ array = (1..50);
This will allocate 50 elements to an array.
The Above Code Will Assign 50 Elements to the array.
We know that many operators above are operated for scalar values, but if we want to operate the scalar values saved in an array, we can use the "array slice", for example, there are 10 values, if We want to assign the value 5 and value 6 in the array to two scales, we can do this:
As we have already seen, we have a wide variety of operators that work with scalar values, but if we wanted to work with arrays we could do what is called "array splicing". Let's say we have an array with 10 values. If we Want to Assign Values 5 and 6 to Two Scalar Values We Could Do The Following:
($ ONE, $ TWO) = @Array [4,5]; # array subscript from 0 #Remember That Arrays Start At Subscript 0.
The above code We divide a comma in the subscript in the composite subscript behind the array name, the subscript specifies a plurality of values in an array (here two values), and assign it to the left. (Here is two scales).
In the above code we just spliced two values from the array. When we do array splicing we use the @ sign, followed by the array name, followed by brackets and the subscripts that you want separated by commas. So instead of having two lines for ................. ..