On 18 May 2000, at 13:00, Sean M. Burke wrote:
{snip}
> "(Note: you should not change the structure of a tree while you are
> traversing it.)"
> 
> ...whichis exactly what you're doing.

Uh Huh! And I did see that. And coincidentally $h->delete() is listed 
under "Structure-Moifying Methods". I had a feeling I'd embarrass 
myself asking about this but at least I'm not stuck anymore.

{snip}

> About your traverser -- note that you don't need to visit nodes in
> both pre- and post-order; and you don't need to visit text nodes; and
> if you're going to delete a node, there's no reason to go visiting all
> its children.  You could just say:
> 
>   my @to_delete;
>   $tree->traverse(
>     [
>       sub { # pre-order traverser
>         if($_[0]->tag() eq 'p') {
>           push @to_delete, $_[0];
>           return HTML::Element::PRUNE; # or just 0 will do
>         }
>         return HTML::Element::OK;
>       },
>       undef, # no post-order
>     ],
>     1 # ignore text nodes -- so our traverser sees only elements
>   );
> 
> A bit ugly, I know.

Ah, but I get the gist of it, and when I get a chance to put it to use 
I'm sure it will become much clearer.

> > Any suggestions? Anything enlightening to read? I did look around 
> > some for some examples of using HTML::Element and didn't find 
> > too much, I found Randal S.'s Oct 98 Web Techniques article on 
> > using it very helpful, anything more l could read?
> 
> Hmm, I'm speaking about HTML::Element and HTML::TreeBuilder at YAPC in
> June, and this discussion (and other recent questions) has been very
> helpful to me in showing what confuses people about HTML::Element.  (I
> am glad that the answer to that is no longer "absolutely everything".)

Well, my questions are square from the middle of the newbie 
category so they might not make a good sample. Especially after I 
realise how badly I've skimmed the documentation.

> I may end up turning the results into an article for /The Perl
> Journal/ -- maybe issue 19 (not the issue that JUST mailed, or the one
> after, but the one after THAT).  At the very least, this should help
> me improve the docs to Element.

Mmm, more articles to read. Yeah, from my point of view the docs 
for Element aren't completely clear but as I mentioned my POV is 
limited at this point.
 
I snipped the ruminations but I'm going to sit down with them this 
weekend and take them as some more learning material. I've 
dabbled in Perl for years but now that I've got a concrete job to 
accomplish I'm diving in headfirst and finally I'm fascinated to no 
end with it. Hopefully I can maintain that long enough to learn 
something useful, I'm finding my attention span is returning to the 
level it was when I was a child...

Thank You


Chris

Reply via email to