in reply to Passing a list as a subroutine's return value ( list of HTML::Element objects )

Remove the $tmp->delete. You're deleting things from within the DOM before trying to return it.

  • Comment on Re: Passing a list as a subroutine's return value ( list of HTML::Element objects )
  • Download Code

Replies are listed 'Best First'.
Re^2: Passing a list as a subroutine's return value ( list of HTML::Element objects )
by ikegami (Patriarch) on Sep 27, 2023 at 13:53 UTC

    Not quite that simple, cause you now have a memory leak. The entire tree is never freed.

Re^2: Passing a list as a subroutine's return value ( list of HTML::Element objects )
by choroba (Cardinal) on Sep 27, 2023 at 09:16 UTC
    Is it enough? Declaring $tmp outside the unescape_entitites sub makes the output even larger and identical to the expected one. So it seems you need to have the HTML::TreeBuilder::XPath object around to be able to access the nodes it matched.

    Update: it seems the difference is the _parent contents which just contains the XPath internals. Disregard this node.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: Passing a list as a subroutine's return value ( list of HTML::Element objects )
by mldvx4 (Friar) on Sep 27, 2023 at 10:21 UTC

    Thanks.

    How can one tell when a 'new' variable is somehow connected to another?

      In general, you don't have to worry about that. As long as you hold a reference, the object will be kept alive. But you called a function which frees the tree including all of its nodes, which it does by hollowing out any existing references to its nodes.