如何使用 Getopt::Long 检索作为选项值传递的确切值?

How do I retrieve the exact value passed as an option value using Getopt::Long?

我正在尝试 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
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