Reputation: 91
I'm using Perl CGI and I'm looking for how to include in the header, the viewport meta, ie the following html line:
<meta name = "viewport"
content = "width = device-width, initial-scale = 1, user-scalable = yes">
The header of my script is as follows:
use strict;
use warnings;
use utf8;
use DBI;
use CGI qw (-any);
use Switch;
my $ cgi = new CGI;
print $ cgi-> header ("text/html; charset=UTF-8");
print $ cgi-> start_html (
-title => 'List of new movies',
-author => '[email protected]',
-lang => 'en',
-meta => {copyleft => '[email protected]'},
-style => {-src => 'https://my-web-server.com/style.css'},
);
Upvotes: 1
Views: 353
Reputation: 382
You can do this (and you need no additional module than your CGI one)
print "Content-type:text/html\n\n";
print qq(
<!DOCTYPE html>
<html>
<head>
<title>Yourwebsite.com</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<more html code here .....>
</body>
</html> );
If you are just beginning with perl/programming, I do not discourage you from using CGI (like others usually do) but I would request you to know its limitation properly, and use/not-use it accordingly.
Upvotes: -2
Reputation: 944444
Don't confuse the HTTP header with the HTML <head>
section.
If you were going to use the CGI module's HTML generating methods, then you would do this in the same way as your copyleft
meta element.
-meta => {
copyleft => '[email protected]',
viewport => 'width=device-width,initial-scale=1,user-scalable=yes'
},
However HTML Generation functions should no longer be used (as per the CGI.pm documentation).
You could replace this code with a template system.
For that matter, you should avoid CGI entirely and use an alternative such as PSGI.
Upvotes: 7