Perl string literals work like single and double quotes in Unix / Linux shells

One reason Perl is shell-friendly is that Perl string literals are similar to Unix / Linux shell single and double quotes. It works like this.

Single quote string

Perl single quoted strings do not interpolate variables. This behavior is the same as the Unix / Linux shell.

#Do not expand variables (hello $name)
my $message ='hello $name';

Double quote string

Perl double quoted strings do variable expansion. This behavior is the same as the Unix / Linux shell.

#Explode variables (hello kimoto)
my $name ='kimoto';
my $hessage = "hello $name";

It works like shell single and double quotes, so it's easy to remember.

What is the difference between Perl and shell string literals?

There are differences between Perl and bash. That is, the backslash "\" is interpreted as an escape sequence. In Perl, you can use "\ n" in double quotes to represent a line break in any Unix / Linux environment. It seems that Perl developers chose the similarity with C language for escape sequences.

Associated Information