Search code examples
perldereference

Dereference a HTML::Element hash reference


I'm looping through an array that has stored some values from HTML::TreeBuilder, where a look_down() was used. When I print $value, I get the below, which I would like dereferenced.

HTML::Element=HASH(0xe687f4)

Doing a print \$value seems to return a generic reference:

REF(0xe6ea84)

What is the symbol/s I need to dereference a HTML::Element hash reference?

Note: Using $$value returns error Not a SCALAR reference

EDIT: Solution found thanks to cjm via comments. I needed print $value->as_HTML


Solution

  • When you have an object (indicated by the "HTML::Element" part of HTML::Element=HASH(0xe687f4)), you should normally access it only through its documented interface. For HTML::Element, important methods include as_HTML (which returns the element and its content as a string of HTML code) and dump (which prints a summary of the contents and is useful for debugging).

    So, if you want to print the HTML you've extracted, use:

    print $value->as_HTML;