Perl Language What is interpolated


Perl interpolates variable names:

my $name = 'Paul';
print "Hello, $name!\n"; # Hello, Paul!

my @char = ('a', 'b', 'c');
print "$char[1]\n"; # b

my %map = (a => 125, b => 1080, c => 11);
print "$map{a}\n"; # 125

Arrays may be interpolated as a whole, their elements are separated by spaces:

my @char = ('a', 'b', 'c');
print "My chars are @char\n"; # My chars are a b c

Perl does not interpolate hashes as a whole:

my %map = (a => 125, b => 1080, c => 11);
print "My map is %map\n"; # My map is %map

and function calls (including constants):

use constant {
    PI => '3.1415926'
print "I like PI\n";         # I like PI
print "I like " . PI . "\n"; # I like 3.1415926

Perl interpolates escape sequences starting with \:

\t                  horizontal tab
\n                  newline
\r                  return
\f                  form feed
\b                  backspace
\a                  alarm (bell)
\e                  escape

Interpolation of \n depends on the system where program is working: it will produce a newline character(s) according to the current system conventions.

Perl does not interpolate \v, which means vertical tab in C and other languages.

Character may be addressed using their codes:

\x{1d11e}     ๐„ž by hexadecimal code
\o{350436}    ๐„ž by octal code
\N{U+1d11e}   ๐„ž by Unicode code point

or Unicode names:


Character with codes from 0x00 to 0xFF in the native encoding may be addressed in a shorter form:

\x0a     hexadecimal
\012     octal

Control character may be addressed using special escape sequences:

\c@      chr(0)
\ca      chr(1)
\cb      chr(2)
\cz      chr(26)
\c[      chr(27)
\c\      chr(28) # Cannot be used at the end of a string
                 # since backslash will interpolate the terminating quote
\c]      chr(29)
\c^      chr(30)
\c_      chr(31)
\c?      chr(127)

Uppercase letters have the same meaning: "\cA" == "\ca".

Interpretation of all escape sequences except for \N{...} may depend on the platform since they use platform- and encoding-dependent codes.