PopperJuan
PopperJuan

Reputation: 195

Passing a xml child node by reference

i'm trying to pass an xml child node by reference in PERL but I keep receiving a "Not a HASH reference at" error

my $global_XMLData = $xml->XMLin($response->content(), ForceArray => ['Parent']);

for my $child(@{$global_XMLData->{Parent})
{
        parseXML(\$child);
}

sub parseXML
{

    my $child= shift;
    $global_bu{bu_id} = $child->{theAttribute};

    # There's about 20-30 more attributes to get, 
    # but for this example, there's only one
}

Now If i pass it by value it works just fine and I do get the data but every time i try to pass it by reference I keep receiving the error. Any help? I just don't want the data to be a copy since it's a rather large xml child node.

Upvotes: 0

Views: 76

Answers (1)

mob
mob

Reputation: 118605

$child is already a reference. You can see this if you call print $child or print ref($child) before the parseXML() call. You should be fine if you just call parseXML($child).

\$child, which is getting passed to the parseXML function, is necessarily a scalar reference, and it doesn't make sense to use it as a hash reference as you do inside parseXML().

Upvotes: 1

Related Questions