开发者

How to make an object into an array reference?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜