Javatpoint Logo
Javatpoint Logo

Perl Operator Types

Perl operators provide values to their operands like numeric, Boolean or string, etc. To choose an appropriate operator, you need to know the value of operands.

We'll discuss following type of operators:

  • Numeric operators
  • String operators
  • Logical operators
  • Bitwise operators
  • Special operators
  • Comparison operators
  • Assignment operators
Perl Operators

Perl Numeric operators

Numeric operators are the standard arithmetic operators like addition (+), subtraction (-), multiplication (*), division (/) and modulo (%), etc.

Perl String operators

String operators are positive and negative regular expression with repetition (=~ and !~) and concatenation ( .).

String Concatenation operator

output:

Hello this is JavaTpoint.

String Repetition operator

output:

Thank You Thank You Thank You.

Here, note that on the right of 'x' it must be an integer.

There should be space on either side of the 'x' operator.

For example,


Perl Logical operators

Logical operators give a Boolean value to their operands. They are (&&, || and or).

&& -> In && operator, if $a is 0, then value of $a && $b must be false irrespective of the value of $b. So perl does not bother to check $b value. This is called short-circuit evaluation.

|| -> In || operator, if $a is non-zero, then value of $a && $b must be true irrespective of the value of $b. So perl does not bother to check $b value.

Example:

Output:

0
12

Perl Bitwise operators

Bitwise operators treat their operands numerically at bit level. These are (<<, >>, &, |, ^, <<=, >>=, &=, |=, ^=).

Every number will be denoted in terms of 0s and 1s. Initially integers will be converted into binary bit and result will be evaluated. Final result will be displayed in the integer form.

Example:

Output:

127
96
31
15

Perl Special operators

The auto-increment (++) operator is a special operator that increments the numeric character itself by 1.

Example:

Output:

10
Y

Perl Comparison operators

The comparison operator compares the values of its operands. These are ( ==, <, <=, >, >=, <=>, !=).

Example:

Output:

Enter your salary:
15000
You are not earning well

Perl Assignment operators

The assignment operator assigns a value to a variable.

These are (=, +=, -=, *=, /=, |=, &=, %=)

Example:

Output:

40
30
30
10
Next TopicPerl if-else





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA