PREP 2013 Question Authoring - Archived

Use of pair of single quotes and double quotes

Re: Use of pair of single quotes and double quotes

by Paul Pearson -
Number of replies: 0
Hi Ravinder,

In Perl, single quotes are for literal strings. For example, in Perl if you use single quotes to write

$a = 8;
$b = 'The value is $a.';
print $b; # print works in Perl, not PG

you will see

The value is $a.

Double quotes in Perl allow for scalar and array variable substitution. So, in Perl if you use double quotes to write

$a = 8;
$b = "The value is $a.";
print $b; # print works in Perl, not PG

you will see

The value is 8.

What does this mean for PG and, in particular, MathObjects? Pretty much the same thing: double quotes allow for variable substitution while single quotes do not. For example,

$a = 8;
$b = Compute('$a'); # should cause an error, though I did not test it

while

$a = 8;
$b = Compute("$a"); # creates a MathObject Real(8).

Good luck and keep the questions coming!

Paul Pearson