Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses


by jonnyfolk (Vicar)
on May 26, 2006 at 16:05 UTC ( #551896=perlquestion: print w/ replies, xml ) Need Help??
jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

I'm experimenting with HTML::TokeParser::Simple, this time trying to parse a document as a scalar. It's not working properly, can someone show me how this should be done, please?
use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; print "Content-type: text/html\n\n"; use HTML::TokeParser::Simple; my $page = 'slices.html'; open FH, $page or die $!; my @file = <FH>; close FH; my $file = join "", @file; my $p = HTML::TokeParser::Simple->new( \$file ); while ( my $token = $p->get_token ) { next unless $token->is_text; my $line = $token->as_is; print $line; }
Update: closed the code tag!!

Comment on HTML::TokeParser::Simple
Download Code
Replies are listed 'Best First'.
Re: HTML::TokeParser::Simple
by wfsp (Abbot) on May 26, 2006 at 16:21 UTC
    Hi jonnyfolk

    It works ok for me. What do you mean by 'not working properly'?

    Do you get any output, error messages? Is there any text in slices.html?

    You could add some more error checking:

    my $p = HTML::TokeParser::Simple->new( \$file ) or die "couldn't parse html: $!";
    That may help reveal any snags.

    It does run all the text into one line because your not printing any tags. Is that what you mean by 'not working properly'?

    Update 2
    You've set warningsToBrowser but you don't have use warnings; turned on (add that line after use strict;). As an aside, if any warnings are returned they are in the html. They won't be displayed in the browser any warnings will be in the error log.

    Update 3
    Corrected where the warnings go.

      Hi wsfp


      Thanks for your input - this is one occasion where I wish my code wasn't working properly!! I have just got back to it and all is working ok - I think I just wasn't connecting properly to the server (there was no error message or time out...)

      I appreciate your getting back to me - sorry for the red herring.

Re: HTML::TokeParser::Simple
by jesuashok (Curate) on May 26, 2006 at 16:12 UTC

    You have not closed the <code> tag.
    I think you have not done preview before posting it.

    "Keep pouring your ideas"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://551896]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-11-28 00:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (735 votes), past polls