Problems? Is your data what you think it is? | |
PerlMonks |
Re: Possible to treat an HTML::TreeBuilder object as a filehandle?by Util (Priest) |
on Feb 13, 2014 at 21:40 UTC ( [id://1074900]=note: print w/replies, xml ) | Need Help?? |
You are barking up the wrong tree. You could make that approach work correctly, but taking data that has already been parsed (by HTML::TreeBuilder in this case), dumping it to an unparsed format (via as_HTML), and reparsing it (via regexes), is a red flag. Even if it was not a bad idea in general, as_HTML does not always output the one-tag-per-line format that your code would need. Your task is complicated by the UL&LI tags not occurring within the SPAN tag. By the time you are processing a LI tag, the author in the previous SPAN tag cannot be directly accessed, since the SPAN is before the LI, but not a parent of LI. Your impulse to iterate over the tags is good. The "my $author;" line would have to be outside the while() loop, though. find_by_tag_name() accepts multiple tag names, and so will do what you need. Working, tested code:
Output: /em
In Section
Seekers of Perl Wisdom
|
|