Thanks for posting the code.

If you want to use the messages method, you need to parse it first, not clean it.

#!/usr/bin/perl use lib '/home/brian/lib/lib/perl/5.8.4'; use strict; use warnings; use HTML::Tidy; open M, "test.html" or die "$!"; my $html = do { local $/; <M> }; my $tidy = new HTML::Tidy; $tidy->parse( "test", $html ); for my $message ( $tidy->messages ) { print $message->as_string, $/; } __END__ output on a test file: test (1:1) Warning: missing <!DOCTYPE> declaration test (8:9) Warning: missing </form> before <option> test (6:1) Warning: <option> isn't allowed in <body> elements test (6:1) Warning: <input> isn't allowed in <body> elements test (12:33) Warning: inserting implicit <form> test (14:17) Warning: discarding unexpected </option> test (12:33) Warning: <form> lacks "action" attribute

If you want the cleaned output, it is edited in-place, ie: $tidy->clean( $html ); # $html now contains tidied output

Update: the clean method returns the clean html, as Aristotle points out below


In reply to Re^3: HTML::Tidy and mysterious HTML::Tidy::Document by bmann
in thread HTML::Tidy and mysterious HTML::Tidy::Document by Cody Pendant

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.