Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

perl

What are operators in Perl?

Sheza Munir

Operators are special symbols that allow the compiler to perform mathematical and logical manipulations. Operators supported by Perl include:

  • arithmetic
  • equality
  • logical
  • assignment
  • bitwise
  • quote-like

Arithmetic operators

Arithmetic operators allow addition, subtraction, multiplication, and division.

Equality operators

Equality operators (also called relational operators) allow us to compare values or variables. They return boolean values.

Logical operators

Logical operators connect expressions to find a compound result. They return boolean values.

Assignment operators

Assignment operators allow values to be stored in a variable. They can be used in conjunction with arithmetic operators.

Bitwise operators

Bitwise operators work bit-by-bit, performing the operation on corresponding bits.

Quote-like operators

Quote-like operators manipulate strings.

Code

The following code shows how some of these operators can be used.

# arithmetic operators
$x = 10;
$y = 3;
print $x+$y,"\n";
print $x-$y,"\n";
print $x*$y,"\n";
print $x/$y,"\n";
print $x%$y,"\n";
print $x**$y,"\n";

# assignment operators
$a = 25;
$b = 8;
$a += $b;
print $a,"\n";
$a -= $b;
print $a,"\n";
$a *= $b;
print $a,"\n";
$a /= $b;
print $a,"\n";
$a %= $b;
print $a,"\n";
$a **= $b;
print $a,"\n";

RELATED TAGS

perl

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring