![]() |
VOOZH | about |
Operators are the foundation of any programming language. Thus, the functionality of Perl programming language is incomplete without the use of operators. A user can define operators as symbols that help to perform specific mathematical and logical computations on operands. String are scalar variables and start with ($) sign in Perl. The String is defined by user within a single quote (') or double quote (") . There are different types of string operators in Perl, as follows:
Concatenation Operator(.)
Perl strings are concatenated with a Dot(.) symbol. The Dot(.) sign is used instead of (+) sign in Perl. This operator takes two scalars variables as operands and combines them in a single scalar variable. Both scalars i.e left and right will convert into a single string.
Example:
Output:
String After Concatenation = GeeksforGeeks
Repetition Operator (x)
The x operator accepts a string on its left-hand side and a number on its right-hand side. It will return the string on the left-hand side repeated as many times as the value on the right-hand side. The repetition depends on the user's input number.
Syntax:
"String" x number_of_times
Example:
Output:
GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks
Note: Possible cases while using the Repetition Operator (x) in String as follows:
Important Point to Remember: Both the Concatenation and Repetition operator can be used with assignment(=) operator as follows:
Example:
Output:
Geeksforgeeks Sudo_PlacementsSudo_PlacementsSudo_PlacementsSudo_PlacementsSudo_Placements
Auto-increment Operator (++)
This operator can also apply to strings. It is a unary operator thats why it will only take a single operand as string. The last character of the operand(i.e string) will increment by one using the ASCII values of characters. The important point to remember about ++ operator that if the string ends with 'z or''Z' then the result of ++ operator will be 'a' or 'A' respectively but the letter to the left of it will also increment by one as well.
Example:
Output:
After ++ : AYZ Again After ++ : AZA
What will happen if we pass an Alpha Numeric string with a number at last and try to increment it ? The number will be incremented by one just like it happened with the previous example -
ABC9
Time Complexity - O(1)
Auxiliary Space - O(1)