Normally, as we said, double-quotes (") are used to delimit the characters in a print statement. However, by replacing the first quote with two q's followed by another character, that final character becomes the new print statement delimiter. Thus, by using "qq!", we tell Perl to use the bang (!) character to delimit the string instead of the double quotes.
For example, without using qq, a print statement that outputs, 'She said, "hi"'. would be written as:
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "She said, \"hi\".";
But with the qq making bang (!) the new delimiter, the same statement can be written as:
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print qq!She said, "hi"!;
Why would we do this? Readability. If the print statement was surrounded with the normal double-quotes, then every double-quote would have to be escaped with a backslash whenever it was used within a string. The backslashes clutter the readability of the string. Thus, we choose a different character to delimit the string in the print statement so that we do not have to escape the double-quotes with backslashes.
|Previous | Next | Table of Contents|