'here' Documents: If we wanted to use Perl to write HTML or any other text, we could code a series of 'print' statements: my $slideshow_title = 'Perl Seminar New York'; print qq(<HTML>), "\n"; print qq( <HEAD>), "\n"; print qq( <TITLE>$slideshow_title</TITLE>), "\n"; print qq( </HEAD>), "\n"; print qq( <BODY>), "\n"; print qq( <H1>Perl writes HTML!</H1>), "\n"; print qq( </BODY>), "\n"; print qq(</HTML>), "\n"; But in Perl, there's more than one way to do it. Use a 'here' document instead: print <<END_HTML; <HTML> <HEAD> <TITLE>$slideshow_title</TITLE> </HEAD> <BODY> <H1>Perl writes HTML!</H1> </BODY> </HTML> END_HTML # Note: print is followed by double <<, tag, semicolon. # Note: closing tag goes on a line by itself. See 'here.pl'
NOTE: If you also include the 'Content-type: text/html' line within the here doc, you MUST have a blank line after it and before any other tags; if you don't have this blank line, you'll get an error and the page won't display.
In other words, this will work:
print <<END_HTML; Content-type: text/html <HTML>
But this will not:
print <<END_HTML; Content-type: text/html <HTML>
10/22/2002