Example:
my $page = $args{'p'};
exit 1 if $page =~ /[^\d\w]/;
print "Content-Type: text/html\n\n";
print "<html><head></head><body>";
require "$page.pl";
somefunc();
print "</body></html>";
在输出开始后使用 require 是否有任何问题,或者所有的 require 都应该位于脚本的顶部?
我不认为这有什么问题。
但是,如果您希望或需要脚本具有更高的一致性,您可以将所需脚本中的代码重写为子例程。例如:
##### old page.pl ######
print "This is the body.<P>\n";
1;
##### old cgi script #####
print "Content-type: text/html\n\n";
print "<html><head></head><body>\n";
require "page.pl";
##### new page.pl ######
sub page_body {
print "This is the body.<P>\n";
}
1;
##### new cgi script #####
require "page.pl"; # now at the top of script
print "Content-type: text/html\n\n";
print "<html><head></head><body>\n";
&page_body;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)