Perl String
Strings are an essential part of the Perl language. They are scalar variables, so they start with ($) sign. A string can be defined within a single quote (‘) or double quote (“).
Perl String Operators
The operators make it easy to manipulate a string in different ways. There are two types of string operators:
- Concatenation (.)
- Repetition (x)
Perl Concatenation Operator
Perl strings are concatenated with a (.) sign instead of (+) sign.
Output:
Christian Grey
Perl Repeitition Operator
Perl strings can be repeated a number of times with (x) variable.
Output:
Thank You Thank You Thank You
Perl Initializing and Declaring a String
In Perl, to declare a string use my keyword before variable name.
A string can be initialised and declared with the following syntax:
In this example, we have shown how to initialize and declare a string. We have printed several strings together by the following ways:
- Join strings using a dot (.) operator.
- Supply strings as separate arguments.
- Embed strings in a bigger string.
We have shown all the three methods to print the output.
Output:
Welcome at tutoraspire. This is our Perl Tutorial. Welcome at tutoraspire. This is our Perl Tutorial. Welcome at tutoraspire. This is our Perl Tutorial.
Perl Formatting Characters in string
Character | Description |
---|---|
a | Bell |
b | Gives a backspace |
cX | Control the characters. X is a character. |
e | escape next character |
E | it ends u, l and q function |
f | Gives formfedd to the string |
l | Transformation of only next letter into lower case. |
L | Transformation of all letters into lower case. |
n | Begins next line from a new line |