Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"


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!!

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-04-27 07:31 GMT
Find Nodes?
    Voting Booth?