English 中文(简体)
环斑script的环境变量
原标题:Environment variable for perl cgi scripts

我有一份大写像如下:

BEGIN {
    unshift (@INC, "$ENV{ HOME }/www/cgi-bin/SiteSpecific");
}

print "Content-type: text/html

";
use SiteObject;
my $siteObjInst = SiteObject->instance();
print $siteObjInst->{HideFields};

这将从指挥中课以罚款,但当从一个浏览器作为加拿大地理统计局的纸面时失败。 或许不会确定ENV{HOME },因为文字无法找到模块。

农研组的文字是否在壳体内操作,没有发现环境变量?

If the above is true, do I need to set the desired variables within the BEGIN block using some other means?

感谢您的帮助。

问题回答

农研中心方案将由网络服务器确定其环境。 视贵国网络服务器的建立情况而定,并且如果安装该服务器,则可能向用户的家名录指出,网络服务器的运行不是你的家名录。

您可从农研中心方案中印刷ENV{HOME}美元,甚至可以更妥善地印刷全部百分比的ENVh,以了解实际发生的情况。

In my experience its better to either hardcode the full path to extra libraries or set the path externally (eg using PERL5LIB). If you re setting it from inside the program, use the "lib" pragma rather than modifying @INC directly:

use lib  /home/user/www/cgi-bin/siteSpecific ;

您肯定能够保证,您的票价和网络服务器的开张功能与$ENV{HOME}相同。 略微把这部法典针对所有人,并尝试:

print "Content-type: text/html

";
print  q[<html><head><title>A Page</title></head>]
    . qq[<body><h1>$HOME=$ENV{HOME}</h1></body></html>]
    ;

甚至:

use strict;
use warnings;
use CGI;

my $q = CGI->new;
print $q->header
    , $q->start_html(  A Page  )
    , $q->start_table
    , $q->Tr( $q->th(  Name  ), $q->th(  Value  ))
    , ( map { $q->Tr( $q->td( $_ ), $q->td( $ENV{$_} )) } sort keys %ENV )
    , $q->end_table
    , $q->end_html
    ;

关于一些问题和潜在答案的清单,我首先请。 我怎么能够打碎我的手稿?





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签