next up previous contents index
Next: Single Quoting Up: Scalar Variables Previous: Scalar Variables   Contents   Index


Double Quoting

Here the string is enclosed in double quotes: ". With double quoting, if a variable appears within the quotes, the value of the variable is used:
  $person = "Sarah";
  $greeting = "Hello, $person";
will cause $greeting to have the value Hello, Sarah. If one wanted to have a literal $ sign within the string, the $ sign must be escaped:
  $count = 33;
  $message = "At this point, \$count is $count";
will result in $message being At this point, $count is 33.

At times, one might want to have literal quotes within a string. These also must be escaped, in order to indicate to Perl that the literal quotes are not the ending quotes of the string:

  $quotation = "Bob said \"Hello\"";
will result in $quotation being set to Bob said "Hello". Such escaping can become tricky - to help in the readability, Perl offers an alternative quoting mechanism:
  $quotation = qq{Bob said "Hello"};
for which the " character need not be escaped. The qq syntax can actually use any pair of brackets, such as qq[] or qq().