Re: How to expand all links.
Gisle Aas (aas@sn.no)
Sun, 03 Dec 1995 15:16:25 +0100
Joseph McDonald wrote:
> # here is my problem: I get:
> # Can't call method "pushContent" without a package or object reference
> # at /usr/local/lib/perl5/HTML/Element.pm line 291.
> #
> # I have tried numerous different ways to call this thing, but keep
> # getting the same answer. In case you can't tell, I haven't yet come
> # to grips with any of perl5's features.
>
> $h->pos(5); # or some random number
> # (is there good way to make sure at a valid point to
> # insert an image?
The argument to $h->pos() should be a reference to a HTML::Element object that
is part of the tree that has $h as root. You might find a suitable location
by traversing the tree.
For instance: Let's find the <body> and set it to be the current position
(untested code).
eval {
$h->traverse(sub { my $e = shift;
# no need to look inside the <head>
return 0 if $e->tag eq 'head';
if ($e->tag eq 'body') {
$h->pos($e);
die; # abort the traverse
}
1;
}, 1);
};
Does anybody know a better way to abort the traverse operation than to die?
> # I think the error actually occurs here, but it won't occur if
> # I take away the pos statement above.
> $h->insertElement($newlink);
--Gisle