Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 845
Sandra Schlichting Avatar asked Apr 17 '26 05:04

Sandra Schlichting


2 Answers

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.

like image 54
Wes Hardaker Avatar answered Apr 18 '26 19:04

Wes Hardaker


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.

like image 26
Dave Sherohman Avatar answered Apr 18 '26 19:04

Dave Sherohman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!