重启Apache后该功能不可用

发布于 2024-10-19 09:03:53 字数 671 浏览 3 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟柳画桥 2024-10-26 09:03:53

Perl 未找到 hw.pm

尝试将此行从startup.pl复制

use lib qw(path to where hw.pm is located);

到hel.pl,替换其中的“use hw;”。但首先要确保路径正确。


@INC - 数组 @INC 包含列表
寻找 Perl 脚本的地方
通过 do EXPR 、 require 进行评估
,或使用构造。最初它
由任何 -I 的参数组成
命令行开关,后跟
默认 Perl 库,可能
“/usr/local/lib/perl”,然后是
“.”,代表当前
目录。

Perl is not finding hw.pm.

Try copying this line from startup.pl

use lib qw(path to where hw.pm is located);

to hel.pl, replacing the "use hw;" there. But first make sure the path is correct.


@INC - The array @INC contains the list
of places to look for Perl scripts to
be evaluated by the do EXPR , require
, or use constructs. It initially
consists of the arguments to any -I
command line switches, followed by the
default Perl library, probably
"/usr/local/lib/perl", followed by
".", to represent the current
directory.

清浅ˋ旧时光 2024-10-26 09:03:53

我设法解决了它。最初我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文