next up previous contents
Next: Operators for Numeric Scalar Up: Scalar Data Previous: Operators for String Scalar   Contents


Quoting Operators

Since many quoted strings contain quotes, perl provides an alternative method of specifying quoted strings. The qq and q operators correspond to the usual double quotes and single quotes, respectively, but, instead of using the quote symbols (" or ') as delimiters, they allow you to use any non-alphanumeric character, or any matching pair of brackets or parentheses, as delimiters. The qq operator, like double quotes, provides variable interpolation, while the q operator does not. You can use these operators to create strings containing quotes without having to use the backslash (\) to escape them, as well as to create quoted strings with embedded newlines.

Thus, instead of typing this:

     $hrefstr = "<a href=\"../$filename\">";
you can use the qq operator:
     $hrefstr = qq{<a href="../$filename">};

There are two other quoting operators that go beyond the capabilities of simple quotes. The qw operator accepts a string consisting of ``words'', separated by whitespace, and returns an array whose elements are each of the words in the string. This is similar to the split function (Section 4.3), but may be more useful when a literal list of words needs to be split. No variable interpolation is performed by the qw operator.

The qx operator first performs variable interpolation, then passes the resulting string to the operating system, returning the output from the execution of the string as a command. This functionality is similar to the backquote operator discussed in Section [*].


next up previous contents
Next: Operators for Numeric Scalar Up: Scalar Data Previous: Operators for String Scalar   Contents
Phil Spector 2002-10-18