PREP 2013 Question Authoring - Archived

Use of pair of single quotes and double quotes

Use of pair of single quotes and double quotes

by Ravinder Kumar -
Number of replies: 1
What is the difference between using single quotes and double quotes? for example 
$f = Formula('x^2 + 1')
$g = Formula (x^3-2*x+1")

In webwork documentation in webwork wiki both are used. I know that in Python both ' ' and  " " are used for strings.
 
In reply to Ravinder Kumar

Re: Use of pair of single quotes and double quotes

by Paul Pearson -
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