Operators


Here are lists of the most commonly used operators and their meanings, with examples.

Table 1. Arithmetic operators

OperatorMeaningExample
+addition$a + $b
-subtraction$a - $b
*multiplication$a * $b
/division$a / $b
%modulus$a % $b
++increment$a++
--decrement$a--

Table 2. Logical operators

OperatorMeaningExample
&&and$a && $b
||or$a || $b
!not!$a

Table 3. Assignment operators

OperatorMeaningExample
=assign$a = $b
+=add to$a +=1
-=subtract from$a -=1
.=append$str.="foo"

Table 4. Relational operators used in string context

OperatorMeaningExample
eqequivalent$str eq "foo"
nenot equivalent$str ne "foo"
gtgreater than$str gt "123"
ltless than$str lt "123"
gegreater than or equal to$str ge "123"
leless than or equal to$str le "123"

Table 5. Relational operators used in numeric context

OperatorMeaningExample
==equivalent$num == 100
!=not equivalent$num! = 100
>greater than$num>100
<less than$num<100
>=greater than or equal to$num>=100
<=less than or equal to$num<=100

Previous Page Table of Content Next Page