next up previous contents index
Next: HERE syntax Up: Scalar Variables Previous: Double Quoting   Contents   Index

Single Quoting

Quoting of strings can also be done by single quotes:
  $name = 'Sarah';
The main difference between double and single quoting is that, with single quoting, no variable substitution is done within the string. Thus, in
  $person = 'Amy';
  $greeting = 'Hello, $person';
the value of $greeting will be Hello, $person. As with double quotes, if you want a single quote to appear in the string, it must be escaped:
  $quote = 'He said to say \'Hello\'';
will cause $quote to be He said to say 'Hello'. There is, analoagous to the qq() syntax for double quotes, a q() syntax for single quotes:
 $quote = q{He said to say 'Hello'};

Another form of quoting that is often useful is the qw() syntax - this is used to extract into a list a group of words, split on embedded whitespace. For example, the construction @names = ('Gerry', 'Sam', 'Joan'); can also be written as @names = qw(Gerry Sam Joan);. normally