use strict;
use warnings;
use HTML::TreeBuilder;
my $HTML_to_parse = shift (@ARGV);
my $tree = HTML::TreeBuilder->new;
$tree->parse($HTML_to_parse);
$tree->eof;
my @paragraph_tags = $tree->look_down('_tag', 'p');
foreach my $p (@paragraph_tags) {
# note that this variable will "hide" the other
# copy of @paragraph_tags and be garbage collected
# as soon as it goes out of scope (the end of the
# while loop)
my @paragraph_tags = $p->look_down('_tag', 'p');
if (scalar (@paragraph_tags) == 1) {
my $tag = shift (@paragraph_tags);
my @contents = $tag->content_list;
my $content = "";
foreach my $con (@contents) {
# check that we have text and not an object
$content .= $con unless (ref $con);
}
print $content;
}
}