Perl
  Home arrow Perl arrow Perl Text: Quoting Without Quote Marks
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl Text: Quoting Without Quote Marks
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2008-03-03


    Table of Contents:
  • Perl Text: Quoting Without Quote Marks
  • Working with the Here Document...Over There
  • Formatting with the Here Document
  • You Can Look But Don't Touch

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Perl Text: Quoting Without Quote Marks
    ( Page 1 of 4 )

    In our last article we introduced you to using text in Perl. By the time we were done, there was text everywhere. But that's okay. In this tutorial we will learn to clean that text up and put it in its place. So roll up those sleeves and prepare to get organized. No more sloppy text for you!

    We left off discussing how to use special characters and escape characters like the newline and tab to determine how our text is displayed. We also talked about the effects of single and double quotes. Here, we will begin by discussing two functions you can use in place of the single and double quote.

    Q...QQ...Q...I Got You!

    Have you ever played a game of cops and robbers with a four year old before? You can't win it. You point your finger at the kid and make the gun sound (q...qq...q...q) and the kid is like NEO from the Matrix. Clearly you shot him; you emptied your whole finger canon at him point blank, but the little punk swears you didn't shoot him. Then he shoots back at you, with his finger pointing at the ceiling and swears he shot you. I mean what the hell? The next thing you know, the couch is tipped over, the kid is crying, and his parents are looking at you like you did something wrong, when clearly, you won the gun fight. And all that whiny kid has to say is: Nuh....UH!

    In addition to using the single and double quotes, you can use the q and qq functions. The q function takes the place of the single quote, while qq takes the place of the double. Here it is in code:


    #!/usr/bin/perl

    print "\n\n";

    print q/How's it going?/;

    print "\n\n";

    print q|What's that over there?|;

    print "nn";

    print qq[And then he said, "How are you?"];

    print "\n\n";

    This results in the print out:

      How's it going?

     

      What's that over there?

      And then he said, “How are you?”

    You will note that we start the function with either a q or qq, and follow it with a delimiter. We then end the quote with the right-side delimiter. The left delimiter can be: <, , /, |, {, or [ and the right delimiter can be: >, /, , |, } or ].

    You can also use these functions when defining a variable:


    #!/usr/bin/perl

    $first=q<That's how you make a single quote>;

    $second=qq{I said, "This is how you make a double quote"};

    print $first;

    print "\n\n";

    print $second;

    Which results in:

      That's how you make a single quote

      I said, “This is how you make a double quote”



     
     
    >>> More Perl Articles          >>> More By James Payne
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT