The here document is a useful facility to make writing html pages in perl easier.
In the last example we had had the following code
# now display the HTML code
print "Content-type: text/html\n\n";
# print the new counter value
print "<html>\n";
print "<body>\n";
print "<h1>You are visitor number $counter </h1>\n";
print "</body>\n";
print "</html>";
We can use a here document to simplify this by removing the print
statements and just using the plain html code.
We add the lines in red so we no longer need the print statements
# now display the HTML code print "Content-type: text/html\n\n"; # print the new counter value print <<htmlpage; <html> <body> <h1>You are visitor number $counter </h1> </body> </html> htmlpage
The name htmlpage is just a variable so it can be pretty much anything you want.
Note1: the here document will even allow $counter to be evaluated.
Note2: always make sure there is at least one blank line after the 'here' document finishes.