Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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中将命令行参数传递给getopt_Perl_Getopt - Fatal编程技术网

如何在perl中将命令行参数传递给getopt

如何在perl中将命令行参数传递给getopt,perl,getopt,Perl,Getopt,我是Perl新手。我必须将命令行参数传递给GetOptions方法,以便访问这些变量。我尝试了以下代码: use Getopt::Long; $result = GetOptions($ARGV[0] => \$serv_name, $ARGV[1] => \$serv_id); print "Server name is $serv_name & server id is $serv_id"; 但我没有得到想要的输出。那么我该如何做到这一点呢?试试这个灵感来自

我是Perl新手。我必须将命令行参数传递给GetOptions方法,以便访问这些变量。我尝试了以下代码:

  use Getopt::Long;
  $result = GetOptions($ARGV[0] => \$serv_name, $ARGV[1] => \$serv_id);
  print "Server name is $serv_name & server id is $serv_id";
但我没有得到想要的输出。那么我该如何做到这一点呢?

试试这个灵感来自:

如果server\u id参数可能不是数字,请将server\u id=i更改为server\u id=s

并通过以下方式调用该程序:

%> perl ex.pl --server_name=the_name --server_id=1234
# or
%> perl ex.pl -server_name the_name -server_id 1234

如何调用该程序?在命令行提示符下,使用perl ex.pl aa 11,其中perl ex.pl-server\u name=xxx-server\u id=yyy或perl ex.pl xxx yyyy,但我仍然在选项spec:server\u name=xxxDid中收到错误lke error,您调用的脚本就像我在示例中所示的那样?@user3839613这个答案有效。在最近的一篇文章中,我们展示了:perl-MGetopt::Long-e'print$Getopt::Long::VERSION'和perl-v@user3839613,谁说在选项规范中使用=xxx?MiguelPrz的代码显然使用了=s。
%> perl ex.pl --server_name=the_name --server_id=1234
# or
%> perl ex.pl -server_name the_name -server_id 1234