Doug Bales has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am new to HTML::TreeBuilder. I know you can use $tree->as_text to obtain a string consisting of all the text nodes from this element and its children. My question is: Is there an easy way to obtain a string of just the text at this node and not its children? Thanks, Doug

Replies are listed 'Best First'.
Re: HTML::TreeBuilder
by integral (Hermit) on Apr 11, 2003 at 16:04 UTC
    Use the $tree->content_list method and concatenate all the non-element nodes, so get just the text for this element. The full list of methods can be seen in the documentation for HTML::Element.
    $text = join '', grep { not ref $_ } $tree->content_list;

    --
    integral, resident of freenode's #perl