Tuesday, 21 July 2015

Perl : Basic Operators and Control Flow

Types of Operator used in the Perl


l. The arithmetic operators +, -, *, and /

Perl also supports three other arithmetic operations:
Exponentiation : exponentiation operator, **, $x = 2 ** 4; =16
The modulo or remainder operation : $x = 25 % 4;
Unary negation : unary negation operator is a - character in front of a single value

2.The comparison operator ==,

if ($a == $b) {
print("$a is equal to $b\n");
}

In Perl, the comparison operators are divided into two classes:
l.Comparison operators that work with numbers

<            Less than
>            Greater than
==          Equal to
<=          Less than or equal to
>=          Greater than or equal to
!=           Not equal to
<=>        Comparison returning 1, 0, or -1


2.Comparison operators that work with strings

lt             Less than                <
gt            Greater than             >
eq           Equal to                  ==
le            Less than or equal to <=
ge           Greater than or equal to >=
ne              Not equal to !=
cmp            Compare, returning 1, 0, or -1 <=>

When Perl is evaluating the expression $a && $b, it first checks whether $a is 0. If $a is 0, $a &&
$b must be false regardless of the value of $b, so Perl doesn't bother checking the value of $b. (This is called short-circuit evaluation.)

3.The assignment operator =

+=   Addition and assignment
-=   Subtraction and assignment
*=   Multiplication and assignment
/=   Division and assignment
%=    Remainder and assignment
**=   Exponentiation and assignment
&=   Bitwise AND and assignment
|=   Bitwise OR and assignment
^=   Bitwise XOR and assignment

4.  The arithmetic operators **, %, and - (unary negation)
5.  The other integer- and string-comparison operators
6.    The logical operators
7. The bit-manipulation operators
8. The assignment operators
7. Auto increment and auto decrement
9. Concatenating and repeating strings

The . operator, which concatenates (joins together) two strings
The x operator, which repeats a string
The .= operator, which combines concatenation and assignment

10. The comma and conditional operators

other operators in the perl
 The comma operator
 The conditional operator

No comments:

Post a Comment