我无法理解引用如何与 subs 中的哈希一起工作。
在这段代码中,我尝试在子程序%config
内部进行更改:handleOptions()
sub handleOption;
my %config = ( gpg => "",
output => "",
pass => "",
host => "",
type => "");
handleOptions(\%config);
print "\n";
print Dumper \%config;
sub handleOptions
{
my ($gpgpath,$type,$pass,$host);
my $pConfig=@_;
GetOptions ("gpg=s" => \$gpgpath,
"type=s" => \$type,
"host=s" => \$type,
"pass=s"=>\$pass);
$pConfig->{'gpg'} = $gpgpath;
$pConfig->{'type'} = $type;
$pConfig->{'pass'} = $pass;
$pConfig->{'host'} = $host;
print Dumper %$pConfig;
}
这是我给--gpg='/home/daryl/gpg/pass.gpg
cli 中的选项时的输出:
$VAR1 = 'pass';
$VAR2 = undef;
$VAR3 = 'gpg';
$VAR4 = '/home/daryl/gpg/pass.gpg';
$VAR5 = 'type';
$VAR6 = undef;
$VAR7 = 'host';
$VAR8 = undef;
$VAR1 = {
'pass' => '',
'gpg' => '',
'type' => '',
'output' => '',
'host' => ''
};
我应该如何进行?