<?xml version="1.0" encoding="windows-1252"?>
<node id="401022" title="Re^3: quotes in Perl" created="2004-10-20 20:00:11" updated="2005-06-13 21:01:21">
<type id="11">
note</type>
<author id="399068">
perlcapt</author>
<data>
<field name="doctext">
&lt;center&gt;&lt;hr /&gt;&lt;/center&gt;
&lt;h3&gt;Here Documents&lt;/h3&gt;
If you want to quote many lines of text literally, you use the "Here Document" notation which consists of an introductory line which has two open angles followed by a keyword, the &lt;b&gt;end tag&lt;/b&gt;, for signalling the end of the quote. All text and lines following the introductory line are quoted. The quote ends when the &lt;b&gt;end tag&lt;/b&gt; is found, by itself, on a line. For example, the end tag is "EOT":
&lt;code&gt;
&lt;font size="-1"&gt;#!/usr/bin/perl -w
use strict;
my $foo = 123.45;
my $bar = "Martha Stewedprune";
print &lt;&lt;"EOT";
=====

This is an example of
   text taken literally
   except that variables are
   expanded where their
   variable names appear.
   foo: $foo
   bar: $bar
EOT
&lt;/code&gt;
This example, when run, produces the following:
&lt;code&gt;
=====

This is an example of
   text taken literally
   except that variables are
   expanded where their
   variable names appear.
   foo: 123.45
   bar: Martha Stewedprune
&lt;/code&gt;
&lt;p&gt;
They way you quote, the end tag is important: like their regular quote counterparts, double-quotes allow expansion of variables and special characters, single quotes don't allow expansion. You may also have a bare, unquoted, end tag; this is equivalent to a double quote, i.e., expansion expansion.
&lt;p&gt;
&lt;i&gt;&lt;b&gt;Some warnings:&lt;/b&gt;&lt;/i&gt; 
&lt;ul&gt;
&lt;li&gt;The end tag specifier must follow the &lt;&lt; without any intermediate space.
&lt;li&gt;The actual end tag must be &lt;b&gt;exactly&lt;/b&gt; the same as in the introduction line.
&lt;li&gt;Don't forget that the introduction line must end with a semicolon, just like any other perl statement.
&lt;/ul&gt;
The here document is particularly useful when embedding HTML in Perl because it increases the readability of the HTML. The quote character is printed out without any escapes. For example:
&lt;code&gt;
my $url = "http://www.maperl.com";
my $text = "Mother of Perl";
print &lt;&lt;"EOT";

&lt;a href="$url"&gt;$text&lt;/a&gt;
EOT
&lt;/code&gt;
Prints just what we would hope:
&lt;code&gt;
&lt;a href="http://www.maperl.com"&gt;Mother of Perl&lt;/a&gt;
&lt;/code&gt;

&lt;br /&gt;
</field>
<field name="root_node">
401006</field>
<field name="parent_node">
401009</field>
</data>
</node>
