Tuesday, 11 March 2014

Quote-like & Miscellaneous Operators



Quote-like Operators:

There are following Quote-like operators supported by Perl language. In the following table, a {} represents any pair of delimiters you choose.
Operator
Description
Example
q{ }
Encloses a string with-in single quotes
q{abcd} gives 'abcd'
qq{ }
Encloses a string with-in double quotes
qq{abcd} gives "abcd"
qx{ }
Encloses a string with-in invert quotes
qx{abcd} gives `abcd`

Miscellaneous Operators:

There are following miscellaneous operators supported by Perl language. Assume variable a holds 10 and variable b holds 20 then:
Operator
Description
Example
.
Binary operator dot (.) concatenates two strings.
If $a="abc", $b="def" then $a.$b will give "abcdef"
x
The repetition operator x returns a string consisting of the left operand repeated the number of times specified by the right operand.
('-' x 3) will give ---.
..
The range operator .. returns a list of values counting (up by ones) from the left value to the right value
(2..5) will give (2, 3, 4, 5)
++
Auto Increment operator increases integer value by one
$a++ will give 11
--
Auto Decrement operator decreases integer value by one
$a-- will give 9
->
The arrow operator is mostly used in dereferencing a method or variable from an object or a class name
$obj->$a is an example to access variable $a from object $obj.

No comments: