recognizing and removing an entity from a text node with HTML::Tree

recognizing and removing an entity from a text node with HTML::Tree

am 05.12.2005 23:30:59 von tbrannon

I thought I sent this a long time ago, but I dont see it in my mail
reader, so i am sending again:
-------------------------------

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 = '

Blah

 hithere 

 

Blah

';

my $element_root = HTML::TreeBuilder->new_from_content($html);

$element_root->objectify_text;

$element_root->dump;
print "\n";

my $target;
$target = ' '; # cant be removed.. even with below commented out
$target = 'hi'; # can be removed...

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;