Perl Quote-like Operators Example

Advertisements


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

OperatorDescriptionExample
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`

Example

Try following example to understand all the quote-like operators available in Perl. Copy and paste 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 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


Advertisements
Advertisements