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>

In reply to finding comments with HTML::Element by rwburden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.