我無法理解引用如何在子文件中使用散列。perl修改子文件中的散列
在這段代碼中,我試圖改變%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 [email protected]_;
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' => ''
};
我應該如何着手?
試試這個:'我的($ pConfig)= @_;' –
完美演示總是使用strict和warnings的價值。 – TLP
'嚴格使用;使用警告;儘管如此,'不會幫助他處理子程序聲明不匹配。 – smithfarm