Rob Dixon wrote:
>
> If you have a fixed piece of HTML that you want to add then
> you would still be better off coding it up using 'new_from_lol',
> but if the content varies then you could package the lines
> above as a subroutine:
>
>
> sub html_element {
>   my $html = shift;
>   my $element = HTML::TreeBuilder->new_from_content($html);
>   $element->look_down('_implicit', undef);
> }
>
>
> and then call it like this
>
>
> my $r = $ele->postinsert(html_element($tag));

Another point: this will work, but will result in a memory
leak as HTML::Treebuilder objects aren't destroyed
automatically when they go out of scope. This way is better:

  sub html_element {
    my $tree = HTML::TreeBuilder->new_from_content(shift);
    my $element = $tree->look_down('_implicit', undef);
    $element->detach;
    $tree->delete;
    $element;
  }

Apologies.

Rob


Reply via email to