in reply to HTML::Element accessing "internal attributes" the proper way
A quick look at the HTML::Element documentation suggests using the content_list method, as in my $date = ($d->content_list)[1]. If there was no element 1 in the content list (as when the element is empty), this will set $date to undef and might produce a warning.
Alternately, your use of content was very close: the content method returns an arrayref or undef, so you want my $date = $d->content->[1] but note that that will crash if the element has no content, so you might want to use eval: my $date = eval { $d->content->[1] } which will set $date to undef (and set $@ to an error about attempting to dereference something that was not a reference) if the element has no content.
(All code obviously untested.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HTML::Element accessing "internal attributes" the proper way
by LanX (Saint) on Dec 25, 2020 at 06:55 UTC | |
by jcb (Parson) on Dec 26, 2020 at 01:30 UTC | |
by LanX (Saint) on Dec 26, 2020 at 02:54 UTC |