Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Using qq

  • "qq" is another Perl trick which helps a programmer solve the double-quote problem by allowing her to change the double-quote delimiter in a print statement.

  • 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.

Printing with Here Documents
Table of Contents
Using the printf and sprintf functions


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers