perl math operators

Perl provides a range of math operators that you can use to perform mathematical operations. Here are some commonly used math operators in Perl:

  • Addition: The addition operator (+) is used to add two numbers together.
  • Subtraction: The subtraction operator (-) is used to subtract one number from another.
  • Multiplication: The multiplication operator (*) is used to multiply two numbers together.
  • Division: The division operator (/) is used to divide one number by another.
  • Modulo: The modulo operator (%) is used to find the remainder of a division operation.
  • Exponentiation: The exponentiation operator () is used to raise a number to a power.

Here are some examples of how you can use these operators in Perl:

my $a = 5;
my $b = 3;

my $sum = $a + $b;        # Addition
my $difference = $a - $b; # Subtraction
my $product = $a * $b;    # Multiplication
my $quotient = $a / $b;   # Division
my $remainder = $a % $b;  # Modulo
my $power = $a  $b;     # Exponentiation

print "Sum: $sum\n";
print "Difference: $difference\n";
print "Product: $product\n";
print "Quotient: $quotient\n";
print "Remainder: $remainder\n";
print "Power: $power\n";

Running this code will output the calculated values for each operation. You can modify the values of $a and $b to perform different calculations.