Single quote string
A single-quote string is a string enclosed in single-quotes. Unlike double quoted string, variable expansion is not done and line break characters You cannot use escape sequences for double quotes such as "\n".
# Single quote string my $name = 'Perl Tutorial Book';
Variable expansion is not performed and the line break character is displayed as it is.
my $message = 'I like $book\n'; # "I like $book\n" is displayed. print $message;
Single quoted strings can be used when you want to explicitly express that they are string constants that do not use variable expansion or line break characters.
Escape sequence of single quoted strings
A list of single-quote string escape sequences.
Escape sequence | Meaning |
---|---|
\' | ' |
\\ | \ |
In single quotes, remember the "\'" that represents a single quote and the "\\" that represents the backslash itself.
my $message = 'I \'m honest Perl User \\';
The explanation page of the escape sequence of the single quote string is as follows.
If you want to copy and paste a string containing single quotes, you can also use single quote operator.