Perl Quote-like Operators Example


There are following Quote-like operators supported by Perl language. In the following table, a {} represents any pair of delimiters you choose.

q{ }Encloses a string with-in single quotesq{abcd} gives 'abcd'
qq{ }Encloses a string with-in double quotesqq{abcd} gives "abcd"
qx{ }Encloses a string with-in invert quotesqx{abcd} gives `abcd`


Try the following example to understand all the quote-like operators available in Perl. Copy and paste the following Perl program in file and execute this program.


$a = 10;
$b = q{a = $a};
print "Value of q{a = \$a} = $b\n";

$b = qq{a = $a};
print "Value of qq{a = \$a} = $b\n";

# unix command execution
$t = qx{date};
print "Value of qx{date} = $t\n";

When the above code is executed, it produces the following result −

Value of q{a = $a} = a = $a
Value of qq{a = $a} = a = 10
Value of qx{date} = Thu Feb 14 08:13:17 MST 2013