I went ahead and implemented an HTML parser to produce a "DOM" in accordance with the aforementioned structure.

Here is the program to produce HTML from that "DOM":

sub htmlize{ my ($tag_name,$dom)=@_; return $dom unless ref $dom; my $html; my %cnt; my $no_text; $html .="<$tag_name"; # print "<$tag_name"; for my $rank (0..$dom->{'_meta_attr_n'}-1){ my $attr_name=$dom->{'_meta_order'}->[$rank]; if($attr_name eq '/'){ $no_text=1; next; } my $attr=$dom->{$attr_name}->[$cnt{$attr_name}||'0']; $attr = join ', ',@$attr if ref $attr; $html .= " $attr_name=\"$attr\""; # print " $attr_name=\"$attr\""; $cnt{$attr_name}++; # in the unlikely event that a child tag a +nd this attr have the same name } $html .= '/' if $no_text; # print '/' if $no_text; $html .= '>'; # print '>'; for my $rank ($dom->{'_meta_attr_n'}..$#{$dom->{'_meta_order'}}){ my $tag_name=$dom->{'_meta_order'}->[$rank]; $html .= htmlize($tag_name,$dom->{$tag_name}->[$cnt{$tag_name} +||'0']); $cnt{$tag_name}++; } $html.="</$tag_name>" if !$no_text; # print "</$tag_name>" if !$no_text; return $html; }

Is this unwieldy compared to the [{'key'=>$key_name, 'value'=>$value},...] structure?


In reply to Re^17: the annoying keys "key" and "value" by jabowery
in thread the annoying keys "key" and "value" by jabowery

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.