I am writing a program to apply a Dreamweaver template to a directory tree of HTML files, among other transformations. In order to make it work, I must find the HTML comments in the template that mark the beginning and end of editable sections. I've been using the HTML package to parse the template file and the files to which the template must be applied, then to generate a new, templatized HTML file. I've had no difficulty finding specific tags with specific attributes, and removing or replacing them, except where I must find a comment tag. HTML::TreeBuilder has given me a tree of the template, but HTML::Element->look_down("_tag", "~comment") returns an empty list (or undef. in scalar context), as does
HTML::Element->look_down("_tag", qr/comment/)
whereas HTML::Element->look_down("_tag", "body"), HTML::Element->look_down("_tag", "title"), etc. works as expected:
open (TEMPLATE, $templatePath) || die "can't open $templatePath: $!";
my $template_tree = HTML::TreeBuilder->new();
$template_tree->parse_file (\*TEMPLATE);
my $first_comment = $template_tree->look_down("_tag", "~comment");
if (not defined $first_comment)
{
warn "No comment found in template\n";
}
prompt>perl -w test.pl
No comment found in template
prompt>