Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
perl需要变量给定的文件_Perl_Require - Fatal编程技术网

perl需要变量给定的文件

perl需要变量给定的文件,perl,require,Perl,Require,我想使用一个模块,使文件的路径位于一个变量中 我尝试使用以下代码: #!/usr/bin/perl -w use strict; use Getopt::Long; my ($library, $zipped, $aid_class_file); GetOptions ("aid_class_file=s" => \$aid_class_file, "res_lib=s" => \$library, "zip"

我想使用一个模块,使文件的路径位于一个变量中

我尝试使用以下代码:

#!/usr/bin/perl -w
use strict;

use Getopt::Long;

my ($library, $zipped, $aid_class_file);
GetOptions ("aid_class_file=s"  =>  \$aid_class_file,
            "res_lib=s"         =>  \$library,
            "zip"               =>  \$zipped);

require $aid_class_file;
但它不起作用。我该怎么做

编辑: 错误消息是:

Can't locate Error.pm in @INC (@INC contains: /usr/lib/perl5/5.8.3/x86_64-linux-thread-multi /usr/lib/perl5/5.8.3 /usr/lib/perl5/site_perl/5.8.3/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.3/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl .) at /nfs/iil/disks/home10/imelam2/learn_flow/flow_to_change/AidClass.pm line 6.
BEGIN failed--compilation aborted at /nfs/iil/disks/home10/imelam2/learn_flow/flow_to_change/AidClass.pm line 6.
Compilation failed in require at statistics.pl line 11.
我想添加名为
AidClass.pm
的文件,而不是
Error.pm

我用这句话跑步:

statistics.pl -aid_class_file="/nfs/iil/disks/home10/imelam2/learn_flow/flow_to_change/AidClass.pm"

你没有说它以什么方式“不起作用”,所以这只是一个猜测

你试过看报纸吗?特别是关于使用变量加载模块的位

如果EXPR是一个空字,则需要 采用“.pm”扩展名并替换 “::”文件名中有“/”, 使其易于加载标准 模块。这种形式的装载 模块不会冒险改变您的 命名空间

换句话说,如果您尝试以下方法:

require Foo::Bar; # a splendid bareword
$class = 'Foo::Bar';
require $class; # $class is not a bareword
#or
require "Foo::Bar"; # not a bareword because of the ""
require函数实际上将 在中查找“Foo/Bar.pm”文件 @INC中指定的目录 数组

但如果你尝试这样做:

require Foo::Bar; # a splendid bareword
$class = 'Foo::Bar';
require $class; # $class is not a bareword
#or
require "Foo::Bar"; # not a bareword because of the ""
require函数将查找 @INC数组中的“Foo::Bar”文件和 会抱怨找不到 “Foo::Bar”在那里。在这种情况下,你可以 做:


您的错误表明AidClass无法找到导致其崩溃的error.pm文件。在AidClass.pm的第6行调用Error.pm:

找不到错误。pm

它正在以下路径上查找它:

/usr/lib/perl5/5.8.3/x86_64-linux-thread-multi
/usr/lib/perl5/5.8.3 /usr/lib/perl5/site_perl/5.8.3/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.3/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl
根据AidClass的使用方式,您可以将其目录作为lib添加到AidClass.pm中,这样它也会在其中查找Error.pm:

use lib '/nfs/iil/disks/home10/imelam2/learn_flow/flow_to_change/';
use Error;

或者,您可以从调用AidClass的脚本中执行此操作,而不是调用
use Error调用
使用AidClass
如果Error.pm在文件夹中,它就可以正常工作。

@Prix,你说得对,thnx。把它作为答案写出来,这样我就可以接受。@llya希望你的问题得到解决:)