如何在运行时加载Perl模块?
发布时间:2020-12-15 22:03:35 所属栏目:大数据 来源:网络整理
导读:我想使用 HTML :: Template模块.但是,它并没有安装在我用来开发CGI脚本的服务器上. 可以在运行时加载模块:我在本地Perl安装中找到Template.pm文件,并将文件上传到我正在使用的服务器. #!/usr/bin/perl -wuse CGI qw(:standard :html4);use CGI::Carp qw(war
|
我想使用
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/htmlnn";
# print the template
print $template->output;
解决方法
这是我做的:
cgi-bin/script.pl
cgi-bin/lib/HTML/Template.pm
在script.pl中(除非你在mod_perl下运行): use FindBin qw( $Bin ); use File::Spec::Functions qw( catfile ); use lib catfile $Bin,'lib'; use HTML::Template; # The rest of your script 如果HTML::Template是真正可选的,请阅读perldoc -f require. 参见perlfaq8 How do I keep my own module/library directory?和What’s the difference between require and use?. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
