1. type http://localhost:81/index1.html in browser 2. error: Error during compilation of /var/www/test/sj3/public_html/index1.html: Global symbol "$user" requires explicit package name at /var/www/test/sj3/public_html/index1.html line 2. context: 1:2: 3:
4: code stack: /usr/share/perl5/HTML/Mason/Interp.pm:450 /usr/share/perl5/HTML/Mason/Request.pm:249 /usr/share/perl5/HTML/Mason/Request.pm:212 /usr/share/perl5/HTML/Mason/ApacheHandler.pm:94 /usr/share/perl5/Class/Container.pm:275 /usr/share/perl5/Class/Container.pm:353 /usr/share/perl5/HTML/Mason/Interp.pm:348 /usr/share/perl5/HTML/Mason/ApacheHandler.pm:874 /usr/share/perl5/HTML/Mason/ApacheHandler.pm:828 (eval 34):8 -e:0
# Listen to other ports Listen 81 ServerAdmin webmaster@localhost DocumentRoot /var/www/test/sj3/public_html PerlSetVar MasonCompRoot /var/www/test/sj3/public_html/ PerlSetVar MasonDataDir /var/www/test/sj3/mason/ Action html-mason /cgi-bin/mason.speedy2 SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler
print %user
#!/usr/bin/perl -w use strict; use HTML::Mason::CGIHandler; { our($user, %session); $user = "bla"; } my $h = HTML::Mason::CGIHandler->new ( data_dir => "$ENV{DOCUMENT_ROOT}/../mason", allow_globals => [qw(%session $user)], ); $h->handle_request;
答案 0 :(得分:2)
如果您必须拥有site wide globals,请在apache处理程序中使用allow_globals声明它们,并在根级autohandler中初始化它们。
答案 1 :(得分:0)
print%user是一个错字。它应该是$ user。
daotoad的建议很好,但我需要一段时间才能更改现有代码
以前的程序员有“/cgi-bin/mason.speedy2”包含所有全局变量和包,然后在/ apache.conf中嵌入/cgi-bin/mason.speedy2(即类似于声明它们) autohandler)。我的问题:/cgi-bin/mason.speedy2正在运行吗?如果它正在运行,为什么没有定义全局变量$ user?