Single and Double Quotes in Perl

PERLServer Side ProgrammingProgramming Scripts

You can use double quotes or single quotes around literal strings as follows −

Example

 Live Demo

#!/usr/bin/perl
print "Hello, world\n";
print 'Hello, world\n';

Output

This will produce the following result −

Hello, world
Hello, world\n$

There is an important difference between single and double-quotes. Only double quotes interpolate variables and special characters such as newlines \n, whereas a single quote does not interpolate any variable or special character. Check below example where we are using $a as a variable to store a value and later printing that value −

Example

 Live Demo

#!/usr/bin/perl
$a = 10;
print "Value of a = $a\n";
print 'Value of a = $a\n';

Output

This will produce the following result −

Value of a = 10
Value of a = $a\n$
raja
Published on 28-Nov-2019 07:42:27
Advertisements