dduncan has asked for the wisdom of the Perl Monks concerning the following question:

Going with HTML Formattext, I ran the script and it works. It displays the text. Now I have a twofold problem: 1) One HTML had tables and the end results was partially good. The text was displayed but the data inside of the tables were not shown: Text TABLE NOT SHOWN 2) I want to save the text. So, I tried to following script. It worked (displayed the text but when I viewed the file afterwards, it was completly blank. Please help me obi-wan! Thanks, you guys are the best :) -Dave
require HTML::TreeBuilder; $tree = HTML::TreeBuilder->new->parse_file("test.htm"); require HTML::FormatText; $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 50); open FH, ">test.htm" or die $1; print $formatter->format($tree); close FH or die $1;

Replies are listed 'Best First'.
Re: HMTL Parser Problem
by ColtsFoot (Chaplain) on Aug 07, 2000 at 18:57 UTC
    Firstly the use of CODE tags would make reading your code
    easier. but having reformatted your code the reason that the
    output file is empty is that you are NOT writing anything to
    it. You perform a
    print $formatter->format($tree);
    that prints to STDOUT but you don't
    print FH $formatter->format($tree);
    to print to your output file Hope this helps
Re: HMTL Parser Problem
by eduardo (Curate) on Aug 07, 2000 at 18:54 UTC
    please, from now on, put everything inside <code> tags, ok?
    require HTML::TreeBuilder; $tree = HTML::TreeBuilder->new->parse_file("test.htm"); require HTML::FormatText; $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 50); open FH, ">test.htm" or die $1; print $formatter->format($tree); close FH or die $1;