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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |