我想将一个哈希引用作为参数从一个perl脚本(script1.pl)传递给另一个perl脚本(script2.pl).这是我的代码的样子:
---------------------------- script1.pl ------------------- --------------
#!/usr/bin/perl -w
use strict;
use warnings;
my %hash = (
'a' => "Harsha",
'b' => "Manager"
);
my $ref = \%hash;
system "perl script2.pl $ref";
Run Code Online (Sandbox Code Playgroud)
---------------------------- script2.pl ------------------- --------------
#!/usr/bin/perl -w
use strict;
use warnings;
my %hash = %{$ARGV[0]};
my $string = "a";
if (exists($hash{$string})){
print "$string = $hash{$string}\n";
}
Run Code Online (Sandbox Code Playgroud)
这是输出错误:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `perl script2.pl HASH(0x8fbed0)'
Run Code Online (Sandbox Code Playgroud)
我无法找出传递参考的正确方法.