Perl Operators   «Prev 

Quote Operators in Perl

The single and double quotation marks are not the only way to quote strings. In fact, if your string has quotation marks in it, you can use a backslash to escape your quotation marks, like this:

$s = "This is a quote, \"The quick brown fox ...\"";

This process is prone to error, though. You can also use the qq operator to make your own quotes:
$s = qq{This is a quote, "The quick brown fox ..."};

You can use any character as the quotation delimiter, except
  1. any alphanumeric characters (0-9, a-z, or A-Z)
  2. underscores
  3. whitespace

If your delimiter is one of the four bracketing pairs,
  1. (round),
  2. <angle>,
  3. [square], or
  4. {curly} ,
you can use them in matched sets. Or, if you use another character, you must use the same character to start and end the quoted code.
For example, all of these are equivalent:
$s =qq{This is a quote, "The quick brown fox ..."};
$s = qq<This is a quote, "The quick brown fox ...">;
$s = qq/This is a quote, "The quick brown fox ..."/;

There are three different types of quote operators:
  1. qq for interpolated strings (like the double quotation marks)
  2. q for non-interpolated strings (like the single quotation marks)
  3. qw for making lists of words that are non-interpolated

The qw operator doesn't have a symbolic equivalent (like "" for qq or '' for q). For example, this code:
@a = qw(This is an array!);

is equivalent to this:
@a = ('This', 'is', 'an', 'array!');

The qw operator creates a list with one element for each of the words in the string. The whitespace in the string is used to delimit each of the words.
But qw is the equivalent of single quotes, so there is no interpolation of Perl variables with qw.