Sie sind auf Seite 1von 10

Perl has quite an array of arithmetic operators.

All of these work on variables that contain


numbers. Many of the operators that are used in the C language are used in Perl as well.

+ (returns the sum of two numbers)


- (returns the difference of two numbers)
* (returns the product of two numbers)
/ (returns the quotient of two numbers)
+= (add a number to a variable)
-= (subtract a number from a variable)
++ (increment a variable by 1)
-- (decrement a variable by 1)

String Manipulation

Some of the operators on numbers have counterparts for strings as well.

. (returns the concatenated, or combined, string of two smaller strings)


.= (appends a string onto a variable)

Logical Operations

These are evaluated as being either True or False(1 or 0), and can help alter the flow of
your program using conditional statements

&& (returns true if the first and second are true)


|| (returns true if the first or the second are true)
! (returns true opposite)

== (returns true if the first is equal to the second)


>
<
>=
<=
Robert
adhi
kusuma
putra
ra thought of leaving his house robert adhi want
photos and writing from right foot stepped
outside the room where where rt rw want to
mate with the goal going into sudirman Thamrin
Kebayoran Lama Petukangan red pal Unilever
bans new market developments Hotel Indonesia
roundabout Gatot Subroto wish to see Television
want to go to the mandir room is always
followed by the army commander was shot from
his room to get out of writing and his
subordinates followed
!=

Robert
adhi
kusuma
putra
ra thought of leaving his house robert adhi want
photos and writing from right foot stepped
outside the room where where rt rw want to
mate with the goal going into sudirman Thamrin
Kebayoran Lama Petukangan red pal Unilever
bans new market developments Hotel Indonesia
roundabout Gatot Subroto wish to see Television
want to go to the mandir room is always
followed by the army commander was shot from
his room to get out of writing and his
subordinates followed
String Logical Operators

The same operators are different when a variable does not contain numbers.

eq (returns true if first string is equal to the second)


ne (return true if first string is NOT equal to the second)

Some examples of these are:

$foo = $a+5;
$foo++;
$foo += 10;
$foo = "fu" . "bar";
$foo .= "bar";

if ($foo==5){}
if ($foo>10){}
if ($foo>2 && $foo<=5){}
if ($foo!=8){}

if ($foo eq "bar"){}
if ($foo ne "foobar"){}

Statement Blocks

As you just saw with the if (){}, the {} represents a statement block. Inside this can be 1
or more instructions. They can be used with flow control statements, such as if to allow
your program to have logical flow.
Flow Control

You can use the if statement together with logical operators and a statement block to add
control to your program. An example is:

if ($foo==5){
print "foo is 5";
}

Any combination of logical operators can be used as long as there is only one end result.
This may mean using more than one set of parentheses.

if (($foo>5) && ($foo!=10)){


print "foo is between 5 and 10";
}

Das könnte Ihnen auch gefallen