Perl Tutorial
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Perl - assignment operators example



The example below shows the usage of assignment and compound assignment operators:

  • = Assignment operator
  • += Addition AND assignment operator
  • -= Subtraction AND assignment operator
  • *= Multiply AND assignment operator
  • /= Division AND assignment operator
  • %= Modulo AND assignment operator
  • **= Exponent AND assignment operator
$a = 25.0;

print("a = $a \n\n");

#Addition AND assignment operator
$a += 5;
print("a += 5 makes a = $a\n");

#Subtraction AND assignment operator
$a -= 8;
print("a -= 8 makes a = $a\n");

#Multiply AND assignment operator
$a *= 4;
print("a *= 4 makes a = $a\n");

#Division AND assignment operator
$a /= 2;
print("a /= 2 makes a = $a\n");

#Modulo AND assignment operator
$a %= 5;
print("a %= 5 makes a = $a\n");

#Exponent AND assignment operator
$a **= 3;
print("a **= 3 makes a = $a\n");

The output of the above code will be:

a = 25 

a += 5 makes a = 30
a -= 8 makes a = 22
a *= 4 makes a = 88
a /= 2 makes a = 44
a %= 5 makes a = 4
a **= 3 makes a = 64

❮ Perl - Operators

5