Perl 如何使用Getopt::Long检索作为选项值传递的确切值?
我试图让模块读取命令行参数,但由于某种原因,当我试图在print语句中打印变量时,它打印的是“1”,而不是传递给变量的值 例如:Perl 如何使用Getopt::Long检索作为选项值传递的确切值?,perl,getopt-long,Perl,Getopt Long,我试图让模块读取命令行参数,但由于某种原因,当我试图在print语句中打印变量时,它打印的是“1”,而不是传递给变量的值 例如: use Getopt::Long; use warnings; GetOptions( 'name1' => \$name, 'address' => \$add, 'phone' => \$phone ); print "My name
use Getopt::Long;
use warnings;
GetOptions(
'name1' => \$name,
'address' => \$add,
'phone' => \$phone
);
print "My name is $name , My address is $add, My phone number is $phone\n"
使用以下命令运行上述代码后:
perl getopt.pl --phone 77881100 --name1 Mart --address Ecity
输出为:
My name is 1 , My address is 1, My phone number is 1
我期望输出为:
My name is Mart , My address is Ecity, My phone number is 77881100
请参阅本手册的
Getopt::Long
部分阅读本部分。简言之:使用'name1=s'=>\$name
等。我衷心支持以下建议:当一个模块的工作方式与您想象的不一样时:-)
use warnings;
use strict;
use Getopt::Long;
GetOptions(
'name1=s' => \my $name,
'address=s' => \my $add,
'phone=s' => \my $phone
);
print "My name is $name, My address is $add, My phone number is $phone\n"