重启Apache后该功能不可用
我对 perl 和 apache 相当陌生,我的代码似乎有一个小问题。
我有 3 个文件:
hw.pm
package hw;
sub calc {
my $num1 = shift;
my $num2 = shift;
return $num1 + $num2;
}
1;
startup.pl
use lib qw(path to where hw.pm is located);
1;
hel.pl
#!/usr/bin/perl -w
use hw;
use CGI qw(:standard);
print header;
my $ans = calc(5,4);
print $ans;
我重新启动 apache 没有问题,但是当我从浏览器中出现错误 Can't located hw.pm in @INC
Startup.pl 是否应该已将其包含在 @INC
中?或者我错过了什么?
我正在使用 perl v5.10.1 和 Apache2 v2.2.16
I am fairly new with perl and apache and seem to be having a small problem with my code.
I have 3 files:
hw.pm
package hw;
sub calc {
my $num1 = shift;
my $num2 = shift;
return $num1 + $num2;
}
1;
startup.pl
use lib qw(path to where hw.pm is located);
1;
hel.pl
#!/usr/bin/perl -w
use hw;
use CGI qw(:standard);
print header;
my $ans = calc(5,4);
print $ans;
I have no problem restarting apache but when I access hel.pl from the browser I get an error Can't locate hw.pm in @INC
Should the startup.pl have already included it in @INC
? Or am I missing something?
I am using perl v5.10.1 and Apache2 v2.2.16
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Perl 未找到
hw.pm
。尝试将此行从startup.pl复制
到hel.pl,替换其中的“
use hw;
”。但首先要确保路径正确。Perl is not finding
hw.pm
.Try copying this line from startup.pl
to hel.pl, replacing the "
use hw;
" there. But first make sure the path is correct.我设法解决了它。最初我在 apache2.conf 中有这个:
PerlRequirestartup.pl
,但添加此代码后:
SetHandler perl 脚本
PerlResponseHandler ModPerl::Registry
Perl选项+ParseHeaders
选项+ExecCGI
我能够从 hel.pl 访问我的模块,
谢谢大家的帮助。
I managed to solve it. initially i had this in my apache2.conf:
PerlRequire startup.pl
but after adding this code:
<Directory /var/www>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>
I was able to access my modules from hel.pl
Thanks guys for your help.