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.

Sr.No. Operator & Description
1

q{ }

Encloses a string with-in single quotes

Example − q{abcd} gives 'abcd'

2

qq{ }

Encloses a string with-in double quotes

Example − qq{abcd} gives "abcd"

3

qx{ }

Encloses a string with-in invert quotes

Example − qx{abcd} gives `abcd`

Example

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

#!/usr/local/bin/perl

$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
perl_operators.htm
Advertisements