Strings are a group of characters, that Contains any number of characters, letters, or special characters. It is a scalar type in Perl.
Strings can be declared with
$variable. It stores, alphabets, characters, and numbers.
How to define string literals in Perl
String literals are declared using the below syntax.
$variable=[string in quotes]
Left side of
= contains string variable
The right side contains a string of characters words or sentences enclosed in double quotes.
- Single quote strings are
‘abc’It does not support variable interpolation and backsplash characters.
$variable = "John"; print 'Welcome, $variable!\n';
- Double quote strings are
Double quote stringssupport variable interpolation and backsplash characters. Variables are interpolated and replaced with their value during execution.
It also contains special characters that have a different meaning.
\t is for the tab,
\n is for the new line.
$variable = "John"; print "Welcome, $variable!\n";
The back quote string is
Perl has inbuilt backspace characters
\n- line break
\r- carriege return
\"- Escape double quote
How do I print a string in Perl?
To print a string in Perl, Please use either print or say functions in Perl. You can use the print function by enclosing a string literal or string variable $variable
What are the 4 basic string operations?
There are basic operations on String.
- the reverse of a string