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
如何从Bash调用Perl构造函数?_Perl_Bash - Fatal编程技术网

如何从Bash调用Perl构造函数?

如何从Bash调用Perl构造函数?,perl,bash,Perl,Bash,我有一个perl文件,它有一个构造函数 #!/usr/bin/perl package ConfigFileReader; sub new { my ($mode, $configFileName) = @ARGV; print $mode; print $configFileName; } 我知道将参数传递给perl脚本就像 helloworld.pl arg1 arg2 argN 现在,如何从命令行调用构造函数new{}?顺便说一句,我在shell脚本中调用

我有一个perl文件,它有一个构造函数

#!/usr/bin/perl

package ConfigFileReader;

sub new {
    my ($mode, $configFileName) = @ARGV;

    print $mode;
    print $configFileName;
}
我知道将参数传递给perl脚本就像

helloworld.pl arg1 arg2 argN
现在,如何从命令行调用构造函数new{}?顺便说一句,我在shell脚本中调用perl文件

#!/bin/bash

x=`helloworld.pl arg1 arg2 argN`;

echo $x;

您可以在perl脚本中调用new:

#!/usr/bin/perl

package ConfigFileReader;

sub new {
    my ($mode, $configFileName) = @ARGV;

    print $mode;
    print $configFileName;
}

my $cfg = new ConfigFileReader(@ARGV); # call new with arguments

您可以在perl脚本中调用new:

#!/usr/bin/perl

package ConfigFileReader;

sub new {
    my ($mode, $configFileName) = @ARGV;

    print $mode;
    print $configFileName;
}

my $cfg = new ConfigFileReader(@ARGV); # call new with arguments

等等,如果我想指定脚本的路径怎么办?我尝试了perl-e helloworld.pl“Use ConfigFileReader;new ConfigFileReader(“arg1”、“arg2”、“arg2”);”但什么也没有发生。我希望当您创建包'ConfigFileReader'时,它位于模块ConfigFileReader.pm中,然后您可以使用以下命令指定该模块的路径:
perl-Ipath\u to\u dir\u containing\u MODULE-e”…
No,您可以将此代码添加到
helloworld.pl
中,或者用就地脚本替换它。可能类似于
perl-MConfigFileReader-e'newConfigFileReader($ARGV[0],$ARGV[1])&需要“helloworld.pl”'arg1 arg2
Wait,如果我想指定脚本的路径怎么办?我尝试了perl-e helloworld.pl“Use ConfigFileReader;new ConfigFileReader(“arg1”、“arg2”、“arg2”);”但什么也没有发生。我希望当您创建包'ConfigFileReader'时,它位于模块ConfigFileReader.pm中,然后您可以使用以下命令指定该模块的路径:
perl-Ipath\u to\u dir\u containing\u MODULE-e”…
No,您可以将此代码添加到
helloworld.pl
中,或者用就地脚本替换它。可能类似于
perl-MConfigFileReader-e'newConfigFileReader($ARGV[0],$ARGV[1])&需要“helloworld.pl”arg1 arg2
为什么构造函数引用
@ARGV
?根据几乎普遍的约定,它应该只接收来自
@
的参数。为什么构造函数引用
@ARGV
?根据几乎普遍的约定,它应该只接收来自
@
的参数。