【发布时间】:2011-01-18 13:47:12
【问题描述】:
我想使用 HTML::Template 模块。但是,它没有安装在我用来开发 CGI 脚本的服务器上。
是否可以在运行时加载模块:我在本地 Perl 安装中找到了 Template.pm 文件,并将该文件上传到我正在使用的服务器。
#!/usr/bin/perl -w
use CGI qw(:standard :html4);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# use HTML::Template;
use Template;
# my $package = "HTML::Template";
# eval {
# (my $pkg = $package) =~ s|::|/|g; # require need a path
# require "$pkg.pm";
# import $package;
# };
# die $@ if( $@ );
# open the HTML template
my $template = HTML::Template->new(filename => 'test.tmpl');
# fill in some parameters in the template
$template->param(home => $ENV{HOME});
$template->param(path => $ENV{PATH});
# send the obligatory Content-Type
print "Content-Type: text/html\n\n";
# print the template
print $template->output;
【问题讨论】:
-
我很困惑。如果您已将 Template.pm 上传到您的服务器,您应该能够在编译时使用 'use' 加载它?
-
我收到一条错误消息:my $template = HTML::Template->new(filename => 'test.tmpl');
-
@coson 还有,错误是什么?
-
您必须取消注释“使用 HTML::Template”这一行并注释掉“使用模板”
-
Can't locate object method "new" via package "HTML::Template" (也许你忘了加载 "HTML::Template"?) 在 testtemplate.pl 第 20 行。另一件事是我的 Perl Windows 安装中有一个 Template.pm 和四个 HTTP.pm,我不确定应该将哪一个用于 HTML::Template 模块
标签: perl installation module