Assignment Operator in Perl

What are the Assignment Operator in perl?

Explanation

Operator Function
= Normal Assignment
+= Add and Assign
-= Subtract and Assign
*= Multiply and Assign
/= Divide and Assign
%= Modulus and Assign
**= Exponent and Assign

Everyone knows how to use the assignment operator (=). There are other operators, when used with "=" gives a different result.

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$a = 50;
$a += 50;
print "Value of a using addition operator: $a n";
print "<br>";
$a %= 8;
print "Value of a using modulus,assign operator: $a n";
Result :

Value of a using addition operator: 100
Value of a using mod,assign operator: 4

The above statement is equivalent to "$a=$a+50", thus displaying the result 100. In the same way, the working of modulus assignment operator is shown to display the remainder as "$a=$a%8" equal to 4.

Ask Questions

Ask Question