recognizing and removing an entity from a text node with HTML::Tree
Terrence Brannon <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.lwp |
|---|---|
| Message-ID | <[email protected]> |
When I set $target in the following program to an obvious string, I can
remove it from any text segment with ease. What I am confused about it why I
cannot set $target to and then remove it just as easily.
use strict;
use warnings;
use HTML::TreeBuilder;
my $html = '<h1>Blah</h1> hithere <p> <br>
<h2>Blah</h2>';
my $element_root = HTML::TreeBuilder->new_from_content($html);
$element_root->objectify_text;
$element_root->dump;
print "\n";
my $target;
$target = ' ';
$target = 'hi';
my @text = $element_root->look_down('_tag' => '~text');
for my $text_node (@text) {
my $tmp = $text_node->attr('text');
warn $tmp;
if ($tmp =~ m!$target!) {
warn 'here';
$tmp =~ s!$target!!g;
$text_node->attr(text => $tmp);
}
}
print "\n";
$element_root->dump;