Re: can't call "traverse" without object?

Marc Langheinrich (marc@ccm.cl.nec.co.jp)
Thu, 26 Mar 1998 09:21:13 +0900


>Can anyone tell me where I'm going wrong here?

I've never used HTML::FormatText before, but just looking at the first few
lines of the HTML::Formatter man page (of which FormatText is a subclass)
shows me:

    Format() takes a HTML::Element as parameter

This means that here:
>     print $formatter->format($res->content);
you give it plain text instead of a reference to an HTML::Element! Take a
look at the HTML::Parser and HTML::TreeBuilder modules to see how you can
build a HTML::Element from raw HTML text.

It could for example look something like this:

if ($res->is_success){
    use HTML::TreeBuilder;
    my $h = HTML::TreeBuilder->new;
    # this will give back a reference to the outermost HTML tag element
    # (i.e. <HTML>...</HTML>)
    my $html_top_element = $h->parse ($res->content);
    print $formatter->format($html_top_element);
} else {
    print "It didn't work.\n"
}


hth

Marc