我正在尝试Getopt::Long模块来读取命令行参数,但出于某种原因,当我尝试在print语句中打印变量时,它会打印' 1'而不是传递给变量的值。
示例:
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
答案 0 :(得分:2)
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"
请参阅Getopt::Long
部分Options with values