相关疑难解决方法(0)

将散列引用作为参数传递给perl脚本中的perl脚本

我想将一个哈希引用作为参数从一个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)

我无法找出传递参考的正确方法.

perl hash reference

1
推荐指数
1
解决办法
1860
查看次数

标签 统计

hash ×1

perl ×1

reference ×1