Perl
  Home arrow Perl arrow Page 2 - 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? 
Google.com  
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 - Working with the Here Document...Over There
    ( Page 2 of 4 )

    Another way that we can quote text without using actual quotes is using the here document, which is great for long strings or paragraphs of text. You specify a here document by using the << followed by a delimiter encased in either single quotes or double quotes (single quotes if there is no variable to be interpreted, double if there is). Here is a sample in code:


    #!/usr/bin/perl

    print <<'MOOSE';

    We the people of the United States, in Order to form a more

    perfect Union, establish Justice, insure domestic Tranquility, provide

    for the common defence, promote the general Welfare, and secure the

    Blessings of Liberty to ourselves and our Posterity, do ordain and

    establish this Constitution for the United States of America.

    MOOSE

    Note that the word MOOSE can be any word you choose. This results in:

      We the people of the United States, in Order to form a more

      perfect Union, establish Justice, insure domestic Tranquility, provide

      for the common defence, promote the general Welfare, and secure the

      Blessings of Liberty to ourselves and our Posterity, do ordain and

      establish this Constitution for the United States of America.

    Now try this code:


    #!/usr/bin/perl

    $country="United States of America";

    print <<'MOOSE';

    We the people of the United States, in Order to form a more

    perfect Union, establish Justice, insure domestic Tranquility, provide

    for the common defence, promote the general Welfare, and secure the

    Blessings of Liberty to ourselves and our Posterity, do ordain and

    establish this Constitution for the $country.

    MOOSE

    If you run this program, you will see the following print-out:

      We the people of the United States, in Order to form a more

      perfect Union, establish Justice, insure domestic Tranquility, provide

      for the common defence, promote the general Welfare, and secure the

      Blessings of Liberty to ourselves and our Posterity, do ordain and

      establish this Constitution for the $country.

    This is because we used the single quote around our delimiter instead of the double quote. The fix is simple:


    #!/usr/bin/perl

    $country="United States of America";

    print <<"MOOSE";

    We the people of the United States, in Order to form a more

    perfect Union, establish Justice, insure domestic Tranquility, provide

    for the common defence, promote the general Welfare, and secure the

    Blessings of Liberty to ourselves and our Posterity, do ordain and

    establish this Constitution for the $country.

    MOOSE

    Now if we run the code it will display:

      We the people of the United States, in Order to form a more

      perfect Union, establish Justice, insure domestic Tranquility, provide

      for the common defence, promote the general Welfare, and secure the

      Blessings of Liberty to ourselves and our Posterity, do ordain and

      establish this Constitution for the United States of America.

    We can also store a here document in a variable:


    #!/usr/bin/perl

    $country="United States of America";

    $con= <<"MOOSE";

    We the people of the United States, in Order to form a more

    perfect Union, establish Justice, insure domestic Tranquility, provide

    for the common defence, promote the general Welfare, and secure the

    Blessings of Liberty to ourselves and our Posterity, do ordain and

    establish this Constitution for the $country.

    MOOSE

    print $con;

    Which results in the same as above:

      We the people of the United States, in Order to form a more

      perfect Union, establish Justice, insure domestic Tranquility, provide

      for the common defence, promote the general Welfare, and secure the

      Blessings of Liberty to ourselves and our Posterity, do ordain and

      establish this Constitution for the United States of America.



     
     
    >>> 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek