This tutorial explains about Perl available Operators

What are arithmetic operators in Perl

Arithmetic operators are used to calculate arithmetic mathematical operations

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Modulus
  • Exponent

Perl Arithmetic Operator

For example, We have operand1(op1)=6 and operand2(op2)=2 values.

OperationSymbolDescriptionResult
Addition+addition of two operands$op1 + $op2 is 8
Substraction-Substraction of two operands$op1 - $op2 is 4
Multiplication*Multiplication of two operands$op1 * $op2 is12
Division/Division of operand1 by Operand2 of two operands$op1 / $op2 is 3
Modulus%Remainder after division$op1 % $op2 is 0
Exponent**Exponent calculation. Operand1 power of operand2$op1 ** $op2 is 36

Here is a Perl Arithmetic Operator Example

my $op1= 4;
my $op2 = 2;

my $result= $op1 + $op2;
print "Addition of $op1 and $op2 is $result \n";

$result= $op1 - $op2;
print "Substraction of $op1 and $op2 is $result \n";

$result= $op1 * $op2;
print "Multiplication of $op1 and $op2 is $result \n";

$result= $op1 / $op2;
print "Division of $op1 and $op2 is $result \n";

$result= $op1 % $op2;
print "Modulus of $op1 and $op2 is $result \n";

$result= $op1 ** $op2;
print "Exponentation of $op1 and $op2 is $result \n";

Output:

Addition of 4 and 2 is 6
Subtraction of 4 and 2 is 2
Multiplication of 4 and 2 is 8
Division of 4 and 2 is 2
Modulus of 4 and 2 is 0
Exponentiation of 4 and 2 is 16

What arithmetic operators are used in Perl scripts?

Arithmetic operators in Perl allow you to do arithmetic calculations on operands. Addition(+), Multiplication, Subtraction, Division, Modulus, and Exponent(power) operators exist for this.

What are arithmetic operators in Perl

there are 6 operators in Per for arithmetic calculations. Addition(+), Multiplication, Subtraction, Division, Modulus, and Exponent(power) operators exist for this.