Hi

Given the code snippet bellow how do I order the output so the meta name is before content

Produces the following output

<meta content="J K Rolling" name="Author" /> <meta content="Harry Potter and the Philosopher's Stone" name="title" +/>

It should be

<meta name="Author" content="J K Rolling" /> <meta name="title" content="Harry Potter and the Philosopher's Stone" +/>
#!/usr/bin/perl use strict; use warnings; use HTML::TreeBuilder; use HTML::Element; my $body =HTML::TreeBuilder->new_from_file(*DATA); print $body->as_HTML('<>&',' ',{}) . "\n"; my %meta= ( "Author"=>"J K Rolling", "title","Harry Potter and the Philosopher's Stone" ); my $head = $body -> find_by_tag_name('_tag', 'head'); for my $m (sort keys %meta) { my $m_el = HTML::Element->new('meta'); $m_el->attr('name',$m); $m_el->attr('content',$meta{$m}); $head->push_content($m_el); } my $out = $body->as_HTML('<>&',' ',{}); print $out; __DATA__ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Hello World</title> </head> <body> <h1> Books by J K Rolling</h1> </body> </html>

In reply to Ordering meta tags with HTML::Element by HeadScratcher

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.