Perl CGI Meta tags
Per http://perldoc.perl.org/CGI.html to make meta tags, the following example is given:
pr开发者_如何转开发int start_html(-head=>meta({-http_equiv => 'Content-Type',-content => 'text/html'}))
However using the following code:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = new CGI;
$cgi->autoEscape(undef);
$cgi->html({-head=>meta({-http_equiv => 'Content-Type',-content => 'text/html',-charset=>'utf-8'}),-title=>'Test'},$cgi->p('test'));
I get the following error:
$ perl test.cgi Undefined subroutine &main::meta called at test.cgi line 8.
I'm trying to generate the following tag:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The meta
sub is not imported automatically when you use CGI;
. Try with
use CGI "meta";
(or ":all"
).
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:all);
my $cgi = new CGI;
$cgi->autoEscape(undef);
$cgi->charset('utf-8');
print
$cgi->start_html(
-head => meta({-http_equiv => 'Content-Type', -content => 'text/html'}),
-title => 'Test'
);
But, are you 100% sure than want use CGI for web development and not something better, like PSGI/Plack?
This post is quite old but the solution is easy: the meta is a method of the object $cgi so use it as method.
your example
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = new CGI;
$cgi->autoEscape(undef);
$cgi->html({-head=>$cgi->meta({-http_equiv => 'Content-Type',-content=>'text/html',-charset=>'utf-8'}),-title=>'Test'},$cgi->p('test'));
I simply added $cgi-> in fromt of meta.
精彩评论