Next up, let's look at how we put in
meta information to our HTML document. In plain ol' HTML, this is done using the <meta> tag and produces a lot of useful stuff like keywords and descriptions of our document for search engines. Again all of these things are
attributes for the
start_html function, so we're simply going to build on our initial program, adding in the meta information like so:
print $cgi->start_html(
-title => 'My CGI.pm Web Page',
-meta => {
'keywords' => 'perl, perl cgi, cgi.pm',
'description' => 'cgi.pm tutorals'
}
);
We're using the
-meta attribute, which in turn is a hash of key / value pairs that make up our meta tags. This could be easily extended to cover any meta tag, simply by adding them to the meta hash. Keywords and description are simply the two most common, and used in this as an example. Let's take a look at the output of our program now, with the
-meta attribute included:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><title>My CGI.pm Web Page</title>
<meta name="keywords" content="perl, perl cgi, cgi.pm" />
<meta name="description" content="cgi.pm tutorials" />
</head><body>
Same HTML document start as last time, but you'll see the generated <meta> tags at the end.