开发者

How to make an object into an array reference?

开发者 https://www.devze.com 2023-02-20 12:04 出处:网络
I have this function array_diff(\\@DNs, \\@prev_DNs); which must take array references as arguments. The problem is that I get prev_DNs as an 开发者_运维技巧object from

I have this function

array_diff(\@DNs, \@prev_DNs);

which must take array references as arguments.

The problem is that I get prev_DNs as an 开发者_运维技巧object from

my $prev_DNs = YAML::Syck::LoadFile('temp-previous_DNs.yaml');
print Dumper $prev_DNs;

which outputs

$VAR1 = [
          'abcdef'
        ];

I have tried with

array_diff(\@DNs, \$prev_DNs);

but that didn't work.

Any suggests on how to pass $prev_DNs an an array reference?


It already is an array reference, actually. So you were actually passsing a reference to the reference by prefixing it with another \. You simply need to pass it as $prev_DNs and it should work.


According to your Data::Dumper output, $prev_DNs is an array reference, so just use

array_diff(\@DNs, $prev_DNs);

Using

array_diff(\@DNs, \$prev_DNs);

passes a reference to the reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消