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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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: 5 stars5 stars5 stars5 stars5 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · Thanks for dropping by to read my article on Perl text formatting. Here we show you...
     

       

    PERL ARTICLES

    - 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
    - Perl: More on Lists and Hashes
    - Perl: Dimensional Lists
    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway